mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Pass shell environment before obtaining virtualenv environment for script execution (PY-17816)
If an IDE is executed not terminal on macOS it doesn't get shell environment and this prevents getting the correct environment by virtualenv activation
This commit is contained in:
@@ -187,25 +187,44 @@ public class EnvironmentUtil {
|
||||
|
||||
LOG.info("loading shell env: " + StringUtil.join(command, " "));
|
||||
|
||||
return runProcessAndReadEnvs(command, envFile, "\0");
|
||||
return dumpProcessEnvToFile(command, envFile, "\0");
|
||||
}
|
||||
finally {
|
||||
FileUtil.delete(envFile);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected Map<String, String> dumpProcessEnvToFile(@NotNull List<String> command, @NotNull File envFile, String lineSeparator)
|
||||
throws Exception {
|
||||
return runProcessAndReadEnvs(command, envFile, lineSeparator);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected static Map<String, String> runProcessAndReadEnvs(@NotNull List<String> command, @NotNull File envFile, String lineSeparator)
|
||||
throws Exception {
|
||||
return runProcessAndReadEnvs(command, null, envFile, lineSeparator);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@NotNull
|
||||
protected static Map<String, String> runProcessAndReadEnvs(@NotNull List<String> command,
|
||||
@Nullable File workingDir,
|
||||
@NotNull File envFile,
|
||||
@Nullable File workingDir,
|
||||
@NotNull File envFile,
|
||||
String lineSeparator) throws Exception {
|
||||
return runProcessAndReadEnvs(command, workingDir, null, envFile, lineSeparator);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected static Map<String, String> runProcessAndReadEnvs(@NotNull List<String> command,
|
||||
@Nullable File workingDir,
|
||||
@Nullable Map<String, String> envs,
|
||||
@NotNull File envFile,
|
||||
String lineSeparator) throws Exception {
|
||||
ProcessBuilder builder = new ProcessBuilder(command).redirectErrorStream(true);
|
||||
if (envs != null) {
|
||||
// we might need default environment for the process to launch correctly
|
||||
builder.environment().putAll(envs);
|
||||
}
|
||||
if (workingDir != null) builder.directory(workingDir);
|
||||
builder.environment().put(DISABLE_OMZ_AUTO_UPDATE, "true");
|
||||
Process process = builder.start();
|
||||
|
||||
@@ -67,6 +67,11 @@ class PyVirtualEnvReader(val virtualEnvSdkPath: String) : EnvironmentUtil.ShellE
|
||||
}
|
||||
}
|
||||
|
||||
override fun dumpProcessEnvToFile(command: MutableList<String>, envFile: File, lineSeparator: String?): MutableMap<String, String> {
|
||||
// pass shell environment for correct virtualenv environment setup (virtualenv expects to be executed from the terminal)
|
||||
return runProcessAndReadEnvs(command, null, EnvironmentUtil.getEnvironmentMap(), envFile, lineSeparator)
|
||||
}
|
||||
|
||||
private fun readVirtualEnvOnWindows(activate: Pair<String, String?>): MutableMap<String, String> {
|
||||
val activateFile = FileUtil.createTempFile("pycharm-virualenv-activate.", ".bat", false)
|
||||
val envFile = FileUtil.createTempFile("pycharm-virualenv-envs.", ".tmp", false)
|
||||
|
||||
Reference in New Issue
Block a user