Don't add all system env variables to the process (PY-21648)
authorDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Wed, 11 Jan 2017 16:43:01 +0000 (17:43 +0100)
committerDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Wed, 11 Jan 2017 16:44:12 +0000 (17:44 +0100)
python/python-terminal/src/com/jetbrains/python/sdk/PyVirtualEnvTerminalCustomizer.kt
python/src/com/jetbrains/python/run/PyVirtualEnvReader.kt
python/src/com/jetbrains/python/run/PythonCommandLineState.java

index a4b0ed7d88a438fd030c1a8d8d48489d1eb8abc4..2bdbb4ce8460ff75ca2ad956943f0c838cc97628 100644 (file)
@@ -65,8 +65,7 @@ class PyVirtualEnvTerminalCustomizer : LocalTerminalCustomizer() {
             // we add only envs that are setup by the activate script, because adding other variables from the different shell
             // can break the actual shell
             envs.putAll(reader.readShellEnv().mapKeys { k -> k.key.toUpperCase() }.filterKeys { k ->
-              k in arrayOf("PATH", "PS1", "VIRTUAL_ENV", "PYTHONHOME", "PROMPT", "_OLD_VIRTUAL_PROMPT", "_OLD_VIRTUAL_PYTHONHOME",
-                           "_OLD_VIRTUAL_PATH")
+              k in PyVirtualEnvReader.virtualEnvVars
             })
           }
         }
index 7b412a228a4565de4cbff00c64b833184c4baeb0..792bcc794ab018f98d92c1f26d03fad9b8ea0ba2 100644 (file)
@@ -31,6 +31,11 @@ import java.io.File
 class PyVirtualEnvReader(val virtualEnvSdkPath: String) : EnvironmentUtil.ShellEnvReader() {
   private val LOG = Logger.getInstance("#com.jetbrains.python.run.PyVirtualEnvReader")
 
+  companion object {
+    val virtualEnvVars = listOf("PATH", "PS1", "VIRTUAL_ENV", "PYTHONHOME", "PROMPT", "_OLD_VIRTUAL_PROMPT", "_OLD_VIRTUAL_PYTHONHOME",
+                                "_OLD_VIRTUAL_PATH")
+  }
+
   // in case of Conda we need to pass an argument to an activate script that tells which exactly environment to activate
   val activate: Pair<String, String?>? = findActivateScript(virtualEnvSdkPath, shell)
 
index 15f25a3d4fc8fadcac3ea2598ec4f4b264eb86a7..102d17048c25004d19d0ad2518de3f6512337a1b 100644 (file)
@@ -73,6 +73,7 @@ import java.io.IOException;
 import java.net.ServerSocket;
 import java.nio.charset.Charset;
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * @author traff, Leonid Shalupov
@@ -304,16 +305,17 @@ public abstract class PythonCommandLineState extends CommandLineState {
       PyVirtualEnvReader reader = new PyVirtualEnvReader(sdkHome);
       if (reader.getActivate() != null) {
         try {
-          env.putAll(reader.readShellEnv());
+          env.putAll(reader.readShellEnv().entrySet().stream().filter((entry) -> PyVirtualEnvReader.Companion.getVirtualEnvVars().contains(entry.getKey())
+          ).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
 
           for (Map.Entry<String, String> e : myConfig.getEnvs().entrySet()) {
             if ("PATH".equals(e.getKey())) {
               env.put(e.getKey(), PythonEnvUtil.appendToPathEnvVar(env.get("PATH"), e.getValue()));
-            } else {
+            }
+            else {
               env.put(e.getKey(), e.getValue());
             }
           }
-
         }
         catch (Exception e) {
           LOG.error("Couldn't read virtualenv variables", e);