mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Command line API cleaned, take 2
This commit is contained in:
@@ -32,8 +32,8 @@ import java.awt.*;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.jetbrains.python.sdk.PythonEnvUtil.PYTHONIOENCODING;
|
||||
import static com.jetbrains.python.sdk.PythonEnvUtil.PYTHONUNBUFFERED;
|
||||
import static com.jetbrains.python.sdk.PythonEnvUtil.setPythonIOEncoding;
|
||||
import static com.jetbrains.python.sdk.PythonEnvUtil.setPythonUnbuffered;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
@@ -152,8 +152,8 @@ public class SphinxBaseCommand {
|
||||
}
|
||||
|
||||
cmd.setPassParentEnvironment(true);
|
||||
cmd.setEnvironment(PYTHONIOENCODING, "utf-8");
|
||||
cmd.setEnvironment(PYTHONUNBUFFERED, "1");
|
||||
setPythonIOEncoding(cmd.getEnvironment(), "utf-8");
|
||||
setPythonUnbuffered(cmd.getEnvironment());
|
||||
|
||||
List<String> pathList = Lists.newArrayList(PythonCommandLineState.getAddedPaths(sdk));
|
||||
pathList.addAll(PythonCommandLineState.collectPythonPath(module));
|
||||
|
||||
@@ -242,6 +242,7 @@ public class BuildoutFacet extends Facet<BuildoutFacetConfiguration> implements
|
||||
}
|
||||
|
||||
public void patchCommandLineForBuildout(GeneralCommandLine commandLine) {
|
||||
Map<String, String> env = commandLine.getEnvironment();
|
||||
ParametersList params = commandLine.getParametersList();
|
||||
// alter execution script
|
||||
ParamsGroup script_params = params.getParamsGroup(PythonCommandLineState.GROUP_SCRIPT);
|
||||
@@ -249,19 +250,18 @@ public class BuildoutFacet extends Facet<BuildoutFacetConfiguration> implements
|
||||
if (script_params.getParameters().size() > 0) {
|
||||
String normal_script = script_params.getParameters().get(0); // expect DjangoUtil.MANAGE_FILE
|
||||
String engulfer_path = PythonHelpersLocator.getHelperPath("pycharm/buildout_engulfer.py");
|
||||
commandLine.setEnvironment("PYCHARM_ENGULF_SCRIPT", getConfiguration().getScriptName());
|
||||
env.put("PYCHARM_ENGULF_SCRIPT", getConfiguration().getScriptName());
|
||||
script_params.getParametersList().replaceOrPrepend(normal_script, engulfer_path);
|
||||
}
|
||||
|
||||
// add pycharm helpers to pythonpath so that fixGetpass is importable
|
||||
PythonEnvUtil.addToPythonPath(commandLine, PythonHelpersLocator.getHelpersRoot().getAbsolutePath());
|
||||
|
||||
PythonEnvUtil.addToPythonPath(env, PythonHelpersLocator.getHelpersRoot().getAbsolutePath());
|
||||
/*
|
||||
// set prependable paths
|
||||
List<String> paths = facet.getAdditionalPythonPath();
|
||||
if (paths != null) {
|
||||
path_value = PyUtil.joinWith(File.pathSeparator, paths);
|
||||
new_env.put("PYCHARM_PREPEND_SYSPATH", path_value);
|
||||
env.put("PYCHARM_PREPEND_SYSPATH", path_value);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -272,7 +272,7 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory<PythonC
|
||||
|
||||
GeneralCommandLine commandLine = new GeneralCommandLine(command);
|
||||
if (env != null) {
|
||||
commandLine.setEnvironment(env);
|
||||
commandLine.getEnvironment().putAll(env);
|
||||
}
|
||||
|
||||
commandLine.getParametersList().set(1, PythonRemoteInterpreterManager.toSystemDependent(new File(data.getHelpersPath(),
|
||||
|
||||
@@ -194,7 +194,7 @@ public class PyDebugRunner extends GenericProgramRunner {
|
||||
}
|
||||
|
||||
if (PyDebuggerOptionsProvider.getInstance(project).isSupportGeventDebugging()) {
|
||||
generalCommandLine.setEnvironment(GEVENT_SUPPORT, "True");
|
||||
generalCommandLine.getEnvironment().put(GEVENT_SUPPORT, "True");
|
||||
}
|
||||
|
||||
final String[] debuggerArgs = new String[]{
|
||||
@@ -214,6 +214,6 @@ public class PyDebugRunner extends GenericProgramRunner {
|
||||
roots.add(contentRoot.getPath());
|
||||
}
|
||||
|
||||
commandLine.setEnvironment(PYCHARM_PROJECT_ROOTS, StringUtil.join(roots, File.pathSeparator));
|
||||
commandLine.getEnvironment().put(PYCHARM_PROJECT_ROOTS, StringUtil.join(roots, File.pathSeparator));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ import com.intellij.openapi.roots.*;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.JarFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import com.jetbrains.python.PythonHelpersLocator;
|
||||
import com.jetbrains.python.console.PyDebugConsoleBuilder;
|
||||
@@ -225,8 +224,6 @@ public abstract class PythonCommandLineState extends CommandLineState {
|
||||
}
|
||||
|
||||
protected void initEnvironment(GeneralCommandLine commandLine) {
|
||||
boolean passParentEnvironment = myConfig.isPassParentEnvs();
|
||||
|
||||
Map<String, String> env = myConfig.getEnvs();
|
||||
if (env == null) {
|
||||
env = new HashMap<String, String>();
|
||||
@@ -234,15 +231,20 @@ public abstract class PythonCommandLineState extends CommandLineState {
|
||||
else {
|
||||
env = new HashMap<String, String>(env);
|
||||
}
|
||||
addPredefinedEnvironmentVariables(env, passParentEnvironment);
|
||||
commandLine.setEnvironment(env);
|
||||
|
||||
commandLine.setEnvironment(PythonEnvUtil.PYTHONUNBUFFERED, "1");
|
||||
commandLine.setEnvironment("PYCHARM_HOSTED", "1");
|
||||
addPredefinedEnvironmentVariables(env, myConfig.isPassParentEnvs());
|
||||
addCommonEnvironmentVariables(env);
|
||||
|
||||
commandLine.setPassParentEnvironment(passParentEnvironment);
|
||||
commandLine.getEnvironment().clear();
|
||||
commandLine.getEnvironment().putAll(env);
|
||||
commandLine.setPassParentEnvironment(myConfig.isPassParentEnvs());
|
||||
|
||||
buildPythonPath(commandLine, passParentEnvironment);
|
||||
buildPythonPath(commandLine, myConfig.isPassParentEnvs());
|
||||
}
|
||||
|
||||
protected static void addCommonEnvironmentVariables(Map<String, String> env) {
|
||||
PythonEnvUtil.setPythonUnbuffered(env);
|
||||
env.put("PYCHARM_HOSTED", "1");
|
||||
}
|
||||
|
||||
public void addPredefinedEnvironmentVariables(Map<String, String> envs, boolean passParentEnvs) {
|
||||
@@ -270,9 +272,7 @@ public abstract class PythonCommandLineState extends CommandLineState {
|
||||
flavor.initPythonPath(commandLine, pathList);
|
||||
}
|
||||
else {
|
||||
Map<String, String> env = ContainerUtil.newHashMap(commandLine.getEnvironment());
|
||||
PythonSdkFlavor.initPythonPath(env, passParentEnvs, pathList);
|
||||
commandLine.setEnvironment(env);
|
||||
PythonSdkFlavor.initPythonPath(commandLine.getEnvironment(), passParentEnvs, pathList);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Base class for tasks which are run from PyCharm with results displayed in a toolwindow (manage.py, setup.py, Sphinx etc).
|
||||
@@ -112,6 +113,7 @@ public class PythonTask {
|
||||
assert scriptParams != null;
|
||||
|
||||
cmd.setPassParentEnvironment(true);
|
||||
Map<String, String> env = cmd.getEnvironment();
|
||||
if (!SystemInfo.isWindows && !PySdkUtil.isRemote(mySdk)) {
|
||||
cmd.setExePath("bash");
|
||||
ParamsGroup bashParams = cmd.getParametersList().addParamsGroupAt(0, "Bash");
|
||||
@@ -129,7 +131,7 @@ public class PythonTask {
|
||||
String pathKey = OSUtil.getPATHenvVariableName();
|
||||
String sysPath = System.getenv().get(pathKey);
|
||||
if (pathKey != null && !StringUtil.isEmpty(sysPath)) {
|
||||
cmd.setEnvironment(pathKey, OSUtil.appendToPATHenvVariable(null, sysPath));
|
||||
env.put(pathKey, OSUtil.appendToPATHenvVariable(null, sysPath));
|
||||
}
|
||||
|
||||
cmd.setExePath(homePath);
|
||||
@@ -137,7 +139,7 @@ public class PythonTask {
|
||||
scriptParams.addParameters(myParameters);
|
||||
}
|
||||
|
||||
cmd.setEnvironment(PythonEnvUtil.PYTHONUNBUFFERED, "1");
|
||||
PythonEnvUtil.setPythonUnbuffered(env);
|
||||
|
||||
List<String> pythonPath = setupPythonPath();
|
||||
PythonCommandLineState.initPythonPath(cmd, true, pythonPath, homePath);
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.jetbrains.python.sdk;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.execution.configurations.GeneralCommandLine;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -64,11 +63,6 @@ public class PythonEnvUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void addPathToEnv(@NotNull GeneralCommandLine cmd, @NotNull String key, @NotNull String value) {
|
||||
String currentPath = cmd.getEnvironment().get(key);
|
||||
cmd.setEnvironment(key, appendToPathEnvVar(currentPath, value));
|
||||
}
|
||||
|
||||
public static void addToPythonPath(@NotNull Map<String, String> env, @NotNull Collection<String> values) {
|
||||
addPathsToEnv(env, PYTHONPATH, values);
|
||||
}
|
||||
@@ -77,13 +71,8 @@ public class PythonEnvUtil {
|
||||
addPathToEnv(env, PYTHONPATH, value);
|
||||
}
|
||||
|
||||
public static void addToPythonPath(@NotNull GeneralCommandLine cmd, @NotNull String value) {
|
||||
addPathToEnv(cmd, PYTHONPATH, value);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static List<String> getPathListFromEnv(@NotNull GeneralCommandLine cmd, @NotNull String envKey) {
|
||||
String pythonPath = cmd.getEnvironment().get(envKey);
|
||||
public static List<String> getPathListFromEnv(@NotNull Map<String, String> env, String envKey) {
|
||||
String pythonPath = env.get(envKey);
|
||||
return pythonPath != null ? Lists.newArrayList(pythonPath.split(File.pathSeparator)) : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -337,8 +337,8 @@ public class PythonSdkType extends SdkType {
|
||||
}
|
||||
String virtualenvBin = bin.getPath();
|
||||
|
||||
String pathValue;
|
||||
Map<String, String> env = commandLine.getEnvironment();
|
||||
String pathValue;
|
||||
if (env.containsKey(PATH)) {
|
||||
pathValue = PythonEnvUtil.appendToPathEnvVar(env.get(PATH), virtualenvBin);
|
||||
}
|
||||
@@ -349,11 +349,10 @@ public class PythonSdkType extends SdkType {
|
||||
else {
|
||||
pathValue = virtualenvBin;
|
||||
}
|
||||
commandLine.setEnvironment(PATH, pathValue);
|
||||
env.put(PATH, pathValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String suggestSdkName(final String currentSdkName, final String sdkHome) {
|
||||
String name = getVersionString(sdkHome);
|
||||
return suggestSdkNameFromVersion(sdkHome, name);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.jetbrains.python.sdk.flavors;
|
||||
|
||||
import com.intellij.execution.configurations.GeneralCommandLine;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import icons.PythonIcons;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -67,6 +68,11 @@ public class IronPythonSdkFlavor extends PythonSdkFlavor {
|
||||
return Collections.singletonList("-X:Frames");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initPythonPath(GeneralCommandLine cmd, Collection<String> path) {
|
||||
initPythonPath(path, cmd.getEnvironment());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initPythonPath(Collection<String> path, Map<String, String> env) {
|
||||
addToEnv("IRONPYTHONPATH", StringUtil.join(path, File.pathSeparator), env);
|
||||
|
||||
@@ -41,8 +41,7 @@ public class JythonSdkFlavor extends PythonSdkFlavor {
|
||||
|
||||
@Override
|
||||
public void initPythonPath(GeneralCommandLine cmd, Collection<String> path) {
|
||||
super.initPythonPath(cmd, path);
|
||||
|
||||
initPythonPath(path, cmd.getEnvironment());
|
||||
ParamsGroup paramGroup = cmd.getParametersList().getParamsGroup(PythonCommandLineState.GROUP_EXE_OPTIONS);
|
||||
assert paramGroup != null;
|
||||
for (String param : paramGroup.getParameters()) {
|
||||
|
||||
@@ -11,7 +11,6 @@ import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.encoding.EncodingManager;
|
||||
import com.intellij.util.PatternUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.jetbrains.python.psi.LanguageLevel;
|
||||
import com.jetbrains.python.sdk.PySdkUtil;
|
||||
import com.jetbrains.python.sdk.PythonEnvUtil;
|
||||
@@ -192,18 +191,11 @@ public abstract class PythonSdkFlavor {
|
||||
}
|
||||
|
||||
public void initPythonPath(GeneralCommandLine cmd, Collection<String> path) {
|
||||
Map<String, String> env = ContainerUtil.newHashMap(cmd.getEnvironment());
|
||||
initPythonPath(path, env);
|
||||
cmd.setEnvironment(env);
|
||||
initPythonPath(path, cmd.getEnvironment());
|
||||
}
|
||||
|
||||
public void initPythonPath(Collection<String> path, Map<String, String> env) {
|
||||
path = appendSystemPythonPath(path);
|
||||
addToEnv(PythonEnvUtil.PYTHONPATH, StringUtil.join(path, File.pathSeparator), env);
|
||||
}
|
||||
|
||||
public static void addToEnv(final String key, String value, Map<String, String> env) {
|
||||
PythonEnvUtil.addPathToEnv(env, key, value);
|
||||
public static void addToEnv(final String key, String value, Map<String, String> envs) {
|
||||
PythonEnvUtil.addPathToEnv(envs, key, value);
|
||||
}
|
||||
|
||||
@SuppressWarnings({"MethodMayBeStatic"})
|
||||
@@ -230,4 +222,9 @@ public abstract class PythonSdkFlavor {
|
||||
public Icon getIcon() {
|
||||
return PythonIcons.Python.Python;
|
||||
}
|
||||
|
||||
public void initPythonPath(Collection<String> path, Map<String, String> env) {
|
||||
path = appendSystemPythonPath(path);
|
||||
addToEnv(PythonEnvUtil.PYTHONPATH, StringUtil.join(path, File.pathSeparator), env);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user