Don't add all system env variables to the process (PY-21648)

This commit is contained in:
Dmitry Trofimov
2017-01-11 17:44:12 +01:00
parent 99294ecb08
commit 6b580f833b
3 changed files with 11 additions and 5 deletions
@@ -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
})
}
}
@@ -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)
@@ -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);