PY-71771: Do not validate SSH interpreters using tools for local paths.

`isValidSdkHome` works for local paths only.
We must use `sdkSeemsValid` instead: it is aware of remote interpreters and usually ignores them if can't validate


(cherry picked from commit 31b42e14518f5a8f7a69ba35e50353f4f4894f42)

IJ-CR-149658

GitOrigin-RevId: b30a6bb5d8a6b9986b0690eabbd0d39da6310f01
This commit is contained in:
Ilya.Kazakevich
2024-11-18 17:26:27 +01:00
committed by intellij-monorepo-bot
parent 3653c3862b
commit 02a8b8e3b6
3 changed files with 25 additions and 4 deletions

View File

@@ -267,6 +267,7 @@ public abstract class PythonSdkFlavor<D extends PyFlavorData> {
*/
@Deprecated
@Nullable
@RequiresBackgroundThread(generateAssertion = false) //No warning yet as there are usages: to be fixed
public static PythonSdkFlavor<?> getFlavor(@Nullable String sdkPath) {
if (sdkPath == null || PythonSdkUtil.isCustomPythonSdkHomePath(sdkPath)) return null;
return tryDetectFlavorByLocalPath(sdkPath);

View File

@@ -27,6 +27,7 @@ import com.intellij.util.PlatformUtils;
import com.intellij.util.xmlb.annotations.Transient;
import com.jetbrains.python.PyBundle;
import com.jetbrains.python.PythonModuleTypeBase;
import com.jetbrains.python.sdk.PySdkExtKt;
import com.jetbrains.python.sdk.PythonEnvUtil;
import com.jetbrains.python.sdk.PythonSdkType;
import com.jetbrains.python.sdk.PythonSdkUtil;
@@ -182,7 +183,7 @@ public abstract class AbstractPythonRunConfiguration<T extends AbstractPythonRun
throw new RuntimeConfigurationError(PyBundle.message("runcfg.unittest.no_sdk"));
}
}
else if (getSdkHome() == null || !PythonSdkType.getInstance().isValidSdkHome(getSdkHome())) {
else if (!PySdkExtKt.getSdkSeemsValid(mySdk)) {
throw new RuntimeConfigurationError(PyBundle.message("runcfg.unittest.no_valid_sdk"));
}
}

View File

@@ -57,6 +57,8 @@ import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.lang.ref.WeakReference;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.*;
@@ -123,9 +125,26 @@ public final class PythonSdkType extends SdkType {
return Collections.emptyList();
}
/**
* This function doesn't support remote SDKs.
*
* @deprecated Use {@link PySdkExtKt#getSdkSeemsValid(Sdk)}
*/
@Override
public boolean isValidSdkHome(final @NotNull String path) {
return PythonSdkFlavor.getFlavor(path) != null;
@Deprecated
@RequiresBackgroundThread(generateAssertion = false) //No warning yet as there are usages: to be fixed
public boolean isValidSdkHome(final @NotNull String localPath) {
try {
return isLocalPathValid(Paths.get(localPath));
}
catch (InvalidPathException e) {
return false;
}
}
@RequiresBackgroundThread(generateAssertion = false) //No warning yet as there are usages: to be fixed
private static boolean isLocalPathValid(@NotNull Path path) {
return PythonSdkFlavor.getFlavor(path.toString()) != null;
}
@Override
@@ -135,7 +154,7 @@ public final class PythonSdkType extends SdkType {
public void validateSelectedFiles(VirtualFile @NotNull [] files) throws Exception {
if (files.length != 0) {
VirtualFile file = files[0];
if (!isLocatedInWsl(file) && !isValidSdkHome(file.getPath())) {
if (!isLocatedInWsl(file) && !isLocalPathValid(file.toNioPath())) {
throw new Exception(PyBundle.message("python.sdk.error.invalid.interpreter.selected", file.getName()));
}
}