diff --git a/python/python-rest/src/com/jetbrains/rest/sphinx/SphinxBaseCommand.java b/python/python-rest/src/com/jetbrains/rest/sphinx/SphinxBaseCommand.java index b688e2d7cc35..86a6a9e0086d 100644 --- a/python/python-rest/src/com/jetbrains/rest/sphinx/SphinxBaseCommand.java +++ b/python/python-rest/src/com/jetbrains/rest/sphinx/SphinxBaseCommand.java @@ -165,7 +165,7 @@ public class SphinxBaseCommand { PythonCommandLineState.initPythonPath(cmd, true, pathList, sdkHomePath); - PythonSdkType.patchCommandLineForVirtualenv(cmd, sdkHomePath, true); + PythonSdkType.patchCommandLineForVirtualenv(cmd, sdk); BuildoutFacet facet = BuildoutFacet.getInstance(module); if (facet != null) { facet.patchCommandLineForBuildout(cmd); diff --git a/python/src/com/jetbrains/python/run/AbstractPythonRunConfiguration.java b/python/src/com/jetbrains/python/run/AbstractPythonRunConfiguration.java index 8c7b802ceb25..0b43802d01bf 100644 --- a/python/src/com/jetbrains/python/run/AbstractPythonRunConfiguration.java +++ b/python/src/com/jetbrains/python/run/AbstractPythonRunConfiguration.java @@ -362,7 +362,7 @@ public abstract class AbstractPythonRunConfiguration - PythonSdkType.patchCommandLineForVirtualenv(commandLine, sdk.homePath, true) + PythonSdkType.patchCommandLineForVirtualenv(commandLine, sdk) commandLine.findExecutableInPath()?.let { commandLine.exePath = it } diff --git a/python/src/com/jetbrains/python/sdk/PythonSdkType.java b/python/src/com/jetbrains/python/sdk/PythonSdkType.java index 4e7b1708d7e1..5ebd553d3b02 100644 --- a/python/src/com/jetbrains/python/sdk/PythonSdkType.java +++ b/python/src/com/jetbrains/python/sdk/PythonSdkType.java @@ -342,12 +342,11 @@ public final class PythonSdkType extends SdkType { /** * Alters PATH so that a virtualenv is activated, if present. * - * @param commandLine what to patch - * @param sdkHome home of SDK we're using - * @param passParentEnvironment iff true, include system paths in PATH + * @param commandLine what to patch + * @param sdk SDK we're using */ - public static void patchCommandLineForVirtualenv(GeneralCommandLine commandLine, String sdkHome, boolean passParentEnvironment) { - final Map virtualEnv = activateVirtualEnv(sdkHome); + public static void patchCommandLineForVirtualenv(@NotNull GeneralCommandLine commandLine, @NotNull Sdk sdk) { + final Map virtualEnv = activateVirtualEnv(sdk); if (!virtualEnv.isEmpty()) { final Map environment = commandLine.getEnvironment(); @@ -361,7 +360,7 @@ public final class PythonSdkType extends SdkType { } } else { - environment.put(key,value); + environment.put(key, value); } } } @@ -544,11 +543,11 @@ public final class PythonSdkType extends SdkType { } @NotNull - public static List getSysPath(String bin_path) throws InvalidSdkException { - String working_dir = new File(bin_path).getParent(); + public static List getSysPath(@NotNull Sdk sdk) throws InvalidSdkException { + String working_dir = new File(sdk.getHomePath()).getParent(); Application application = ApplicationManager.getApplication(); if (application != null && (!application.isUnitTestMode() || ApplicationInfoImpl.isInStressTest())) { - return getSysPathsFromScript(bin_path); + return getSysPathsFromScript(sdk); } else { // mock sdk List ret = new ArrayList<>(1); @@ -558,12 +557,13 @@ public final class PythonSdkType extends SdkType { } @NotNull - public static List getSysPathsFromScript(@NotNull String binaryPath) throws InvalidSdkException { + public static List getSysPathsFromScript(@NotNull Sdk sdk) throws InvalidSdkException { // to handle the situation when PYTHONPATH contains ., we need to run the syspath script in the // directory of the script itself - otherwise the dir in which we run the script (e.g. /usr/bin) will be added to SDK path + final String binaryPath = sdk.getHomePath(); GeneralCommandLine cmd = PythonHelper.SYSPATH.newCommandLine(binaryPath, Lists.newArrayList()); final ProcessOutput runResult = PySdkUtil.getProcessOutput(cmd, new File(binaryPath).getParent(), - activateVirtualEnv(binaryPath), MINUTE); + activateVirtualEnv(sdk), MINUTE); if (!runResult.checkSuccess(LOG)) { throw new InvalidSdkException(String.format("Failed to determine Python's sys.path value:\nSTDOUT: %s\nSTDERR: %s", runResult.getStdout(), diff --git a/python/src/com/jetbrains/python/sdk/PythonSdkUpdater.java b/python/src/com/jetbrains/python/sdk/PythonSdkUpdater.java index 243e8c33d5b7..e30ad420120e 100644 --- a/python/src/com/jetbrains/python/sdk/PythonSdkUpdater.java +++ b/python/src/com/jetbrains/python/sdk/PythonSdkUpdater.java @@ -450,7 +450,7 @@ public class PythonSdkUpdater implements StartupActivity { throw new IllegalArgumentException("Cannot evaluate sys.path for remote Python interpreter " + sdk); } final long startTime = System.currentTimeMillis(); - final List sysPath = PythonSdkType.getSysPath(sdk.getHomePath()); + final List sysPath = PythonSdkType.getSysPath(sdk); LOG.info("Updating sys.path took " + (System.currentTimeMillis() - startTime) + " ms"); return sysPath; } diff --git a/python/testSrc/com/jetbrains/env/python/typeshed/PyTypeShedTestCase.kt b/python/testSrc/com/jetbrains/env/python/typeshed/PyTypeShedTestCase.kt index 6a0fe5cbbc93..38994485f6bb 100644 --- a/python/testSrc/com/jetbrains/env/python/typeshed/PyTypeShedTestCase.kt +++ b/python/testSrc/com/jetbrains/env/python/typeshed/PyTypeShedTestCase.kt @@ -85,7 +85,7 @@ abstract class PyTypeShedTestCase(protected val path: String, protected val sdkP }) val sdk = sdkVar ?: return null val modificator = sdk.sdkModificator - val paths = PythonSdkType.getSysPathsFromScript(sdkPath) + val paths = PythonSdkType.getSysPathsFromScript(sdk) PythonSdkUpdater.filterRootPaths(sdk, paths, project).forEach { modificator.addRoot(it, OrderRootType.CLASSES) } diff --git a/python/tools/src/com/jetbrains/python/tools/sdkTools/PySdkTools.java b/python/tools/src/com/jetbrains/python/tools/sdkTools/PySdkTools.java index f7a342d1883e..043efce31d5e 100644 --- a/python/tools/src/com/jetbrains/python/tools/sdkTools/PySdkTools.java +++ b/python/tools/src/com/jetbrains/python/tools/sdkTools/PySdkTools.java @@ -41,7 +41,7 @@ import java.io.IOException; /** * Engine to create SDK for tests. - * See {@link #createTempSdk(com.intellij.openapi.vfs.VirtualFile, SdkCreationType, com.intellij.openapi.module.Module)} + * See {@link #createTempSdk(VirtualFile, SdkCreationType, Module)} * * @author Ilya.Kazakevich */ @@ -112,7 +112,7 @@ public final class PySdkTools { modificator.setSdkAdditionalData(new PythonSdkAdditionalData(PythonSdkFlavor.getFlavor(sdk))); - for (final String path : PythonSdkType.getSysPathsFromScript(sdk.getHomePath())) { + for (final String path : PythonSdkType.getSysPathsFromScript(sdk)) { addTestSdkRoot(modificator, path); } if (!addSkeletons) {