From b3436a8799fb459c9c128edd3ca1818891a441ad Mon Sep 17 00:00:00 2001 From: Semyon Proshev Date: Wed, 20 Mar 2019 17:19:14 +0300 Subject: [PATCH] Increase number of correct env activation (PY-34267) --- .../quickfix/GenerateBinaryStubsFix.java | 6 +++--- .../com/jetbrains/python/sdk/PythonSdkType.java | 15 +-------------- .../python/sdk/skeletons/PySkeletonGenerator.java | 8 ++++---- 3 files changed, 8 insertions(+), 21 deletions(-) diff --git a/python/src/com/jetbrains/python/inspections/quickfix/GenerateBinaryStubsFix.java b/python/src/com/jetbrains/python/inspections/quickfix/GenerateBinaryStubsFix.java index 471eb56bbe1f..f30d7615a7f7 100644 --- a/python/src/com/jetbrains/python/inspections/quickfix/GenerateBinaryStubsFix.java +++ b/python/src/com/jetbrains/python/inspections/quickfix/GenerateBinaryStubsFix.java @@ -67,7 +67,7 @@ public class GenerateBinaryStubsFix implements LocalQuickFix { /** * Generates pack of fixes available for some unresolved import statement. - * Be sure to call {@link #isApplicable(com.jetbrains.python.psi.PyImportStatementBase)} first to make sure this statement is supported + * Be sure to call {@link #isApplicable(PyImportStatementBase)} first to make sure this statement is supported * * @param importStatementBase statement to fix * @return pack of fixes @@ -90,7 +90,7 @@ public class GenerateBinaryStubsFix implements LocalQuickFix { /** * @param importStatementBase statement to fix - * @param qualifiedName name should be fixed (one of {@link com.jetbrains.python.psi.PyImportStatementBase#getFullyQualifiedObjectNames()}) + * @param qualifiedName name should be fixed (one of {@link PyImportStatementBase#getFullyQualifiedObjectNames()}) */ private GenerateBinaryStubsFix(@NotNull final PyImportStatementBase importStatementBase, @NotNull final String qualifiedName) { myQualifiedName = qualifiedName; @@ -175,7 +175,7 @@ public class GenerateBinaryStubsFix implements LocalQuickFix { GeneralCommandLine cmd = PythonHelper.EXTRA_SYSPATH.newCommandLine(homePath, Lists.newArrayList(myQualifiedName)); final ProcessOutput runResult = PySdkUtil.getProcessOutput(cmd, new File(homePath).getParent(), - PythonSdkType.getVirtualEnvExtraEnv(homePath), 5000 + PythonSdkType.activateVirtualEnv(homePath), 5000 ); if (runResult.getExitCode() == 0 && !runResult.isTimeout()) { final String extraPath = runResult.getStdout(); diff --git a/python/src/com/jetbrains/python/sdk/PythonSdkType.java b/python/src/com/jetbrains/python/sdk/PythonSdkType.java index da9de4bcf6b4..be8c08cad1c5 100644 --- a/python/src/com/jetbrains/python/sdk/PythonSdkType.java +++ b/python/src/com/jetbrains/python/sdk/PythonSdkType.java @@ -1,7 +1,6 @@ // Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.jetbrains.python.sdk; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import com.intellij.execution.ExecutionException; import com.intellij.execution.configurations.GeneralCommandLine; @@ -571,7 +570,7 @@ public final class PythonSdkType extends SdkType { // directory of the script itself - otherwise the dir in which we run the script (e.g. /usr/bin) will be added to SDK path GeneralCommandLine cmd = PythonHelper.SYSPATH.newCommandLine(binaryPath, Lists.newArrayList()); final ProcessOutput runResult = PySdkUtil.getProcessOutput(cmd, new File(binaryPath).getParent(), - getVirtualEnvExtraEnv(binaryPath), MINUTE); + activateVirtualEnv(binaryPath), MINUTE); if (!runResult.checkSuccess(LOG)) { throw new InvalidSdkException(String.format("Failed to determine Python's sys.path value:\nSTDOUT: %s\nSTDERR: %s", runResult.getStdout(), @@ -580,18 +579,6 @@ public final class PythonSdkType extends SdkType { return runResult.getStdoutLines(); } - /** - * Returns a piece of env good as additional env for getProcessOutput. - */ - @Nullable - public static Map getVirtualEnvExtraEnv(@NotNull String binaryPath) { - final File root = getVirtualEnvRoot(binaryPath); - if (root != null) { - return ImmutableMap.of("PATH", root.toString()); - } - return null; - } - @Nullable @Override public String getVersionString(@NotNull Sdk sdk) { diff --git a/python/src/com/jetbrains/python/sdk/skeletons/PySkeletonGenerator.java b/python/src/com/jetbrains/python/sdk/skeletons/PySkeletonGenerator.java index cc59b8a61fc5..9afcd007fd69 100644 --- a/python/src/com/jetbrains/python/sdk/skeletons/PySkeletonGenerator.java +++ b/python/src/com/jetbrains/python/sdk/skeletons/PySkeletonGenerator.java @@ -151,8 +151,8 @@ public class PySkeletonGenerator { final String parent_dir = new File(binaryPath).getParent(); List commandLine = buildSkeletonGeneratorCommandLine(modname, modfilename, assemblyRefs, binaryPath, extraSyspath); - final Map extraEnv = PythonSdkType.getVirtualEnvExtraEnv(binaryPath); - final Map env = new HashMap<>(extraEnv != null ? PySdkUtil.mergeEnvVariables(myEnv, extraEnv) : myEnv); + final Map extraEnv = PythonSdkType.activateVirtualEnv(binaryPath); + final Map env = new HashMap<>(!extraEnv.isEmpty() ? PySdkUtil.mergeEnvVariables(myEnv, extraEnv) : myEnv); if (myPrebuilt) { env.put("IS_PREGENERATED_SKELETONS", "1"); @@ -212,7 +212,7 @@ public class PySkeletonGenerator { "-d", mySkeletonsPath, // output dir "-b", // for builtins }, - PythonSdkType.getVirtualEnvExtraEnv(binaryPath), MINUTE * 5 + PythonSdkType.activateVirtualEnv(binaryPath), MINUTE * 5 ); runResult.checkSuccess(LOG); LOG.info("Rebuilding builtin skeletons took " + (System.currentTimeMillis() - startTime) + " ms"); @@ -233,7 +233,7 @@ public class PySkeletonGenerator { final ProcessOutput process = getProcessOutput(parentDir, ArrayUtil.toStringArray(cmd), - PythonSdkType.getVirtualEnvExtraEnv(homePath), + PythonSdkType.activateVirtualEnv(homePath), MINUTE * 4); // see PY-3898 LOG.info("Retrieving binary module list took " + (System.currentTimeMillis() - startTime) + " ms");