use of com.jetbrains.python.buildout.BuildoutFacet in project intellij-community by JetBrains.
the class SphinxBaseCommand method createCommandLine.
protected GeneralCommandLine createCommandLine(Module module, List<String> params) throws ExecutionException {
Sdk sdk = PythonSdkType.findPythonSdk(module);
if (sdk == null) {
throw new ExecutionException("No sdk specified");
}
ReSTService service = ReSTService.getInstance(module);
String sdkHomePath = sdk.getHomePath();
GeneralCommandLine cmd = new GeneralCommandLine();
if (sdkHomePath != null) {
final String runnerName = "sphinx-quickstart" + (SystemInfo.isWindows ? ".exe" : "");
String executablePath = PythonSdkType.getExecutablePath(sdkHomePath, runnerName);
if (executablePath != null) {
cmd.setExePath(executablePath);
} else {
cmd = PythonHelper.LOAD_ENTRY_POINT.newCommandLine(sdkHomePath, Lists.<String>newArrayList());
}
}
cmd.setWorkDirectory(service.getWorkdir().isEmpty() ? module.getProject().getBaseDir().getPath() : service.getWorkdir());
PythonCommandLineState.createStandardGroups(cmd);
ParamsGroup scriptParams = cmd.getParametersList().getParamsGroup(PythonCommandLineState.GROUP_SCRIPT);
assert scriptParams != null;
if (params != null) {
for (String p : params) {
scriptParams.addParameter(p);
}
}
final Map<String, String> env = cmd.getEnvironment();
setPythonIOEncoding(env, "utf-8");
setPythonUnbuffered(env);
if (sdkHomePath != null) {
resetHomePathChanges(sdkHomePath, env);
}
env.put("PYCHARM_EP_DIST", "Sphinx");
env.put("PYCHARM_EP_NAME", "sphinx-quickstart");
List<String> pathList = Lists.newArrayList(PythonCommandLineState.getAddedPaths(sdk));
pathList.addAll(PythonCommandLineState.collectPythonPath(module));
PythonCommandLineState.initPythonPath(cmd, true, pathList, sdkHomePath);
PythonSdkType.patchCommandLineForVirtualenv(cmd, sdkHomePath, true);
BuildoutFacet facet = BuildoutFacet.getInstance(module);
if (facet != null) {
facet.patchCommandLineForBuildout(cmd);
}
return cmd;
}
use of com.jetbrains.python.buildout.BuildoutFacet in project intellij-community by JetBrains.
the class PythonTask method createCommandLine.
public GeneralCommandLine createCommandLine() {
GeneralCommandLine cmd = new GeneralCommandLine();
if (myWorkingDirectory != null) {
cmd.setWorkDirectory(myWorkingDirectory);
}
String homePath = mySdk.getHomePath();
if (homePath != null) {
homePath = FileUtil.toSystemDependentName(homePath);
}
PythonCommandLineState.createStandardGroups(cmd);
ParamsGroup scriptParams = cmd.getParametersList().getParamsGroup(PythonCommandLineState.GROUP_SCRIPT);
assert scriptParams != null;
Map<String, String> env = cmd.getEnvironment();
if (!SystemInfo.isWindows && !PySdkUtil.isRemote(mySdk)) {
cmd.setExePath("bash");
ParamsGroup bashParams = cmd.getParametersList().addParamsGroupAt(0, "Bash");
bashParams.addParameter("-cl");
NotNullFunction<String, String> escaperFunction = StringUtil.escaper(false, "|>$\"'& ");
StringBuilder paramString;
if (myHelper != null) {
paramString = new StringBuilder(escaperFunction.fun(homePath) + " " + escaperFunction.fun(myHelper.asParamString()));
myHelper.addToPythonPath(cmd.getEnvironment());
} else {
paramString = new StringBuilder(escaperFunction.fun(homePath) + " " + escaperFunction.fun(myRunnerScript));
}
for (String p : myParameters) {
paramString.append(" ").append(p);
}
bashParams.addParameter(paramString.toString());
} else {
cmd.setExePath(homePath);
if (myHelper != null) {
myHelper.addToGroup(scriptParams, cmd);
} else {
scriptParams.addParameter(myRunnerScript);
}
scriptParams.addParameters(myParameters.stream().filter(o -> o != null).collect(Collectors.toList()));
}
PythonEnvUtil.setPythonUnbuffered(env);
if (homePath != null) {
PythonEnvUtil.resetHomePathChanges(homePath, env);
}
List<String> pythonPath = setupPythonPath();
PythonCommandLineState.initPythonPath(cmd, true, pythonPath, homePath);
BuildoutFacet facet = BuildoutFacet.getInstance(myModule);
if (facet != null) {
facet.patchCommandLineForBuildout(cmd);
}
return cmd;
}
use of com.jetbrains.python.buildout.BuildoutFacet in project intellij-community by JetBrains.
the class PydevConsoleRunnerFactory method createConsoleRunner.
@Override
@NotNull
public PydevConsoleRunnerImpl createConsoleRunner(@NotNull Project project, @Nullable Module contextModule) {
Pair<Sdk, Module> sdkAndModule = PydevConsoleRunner.findPythonSdkAndModule(project, contextModule);
Module module = sdkAndModule.second;
Sdk sdk = sdkAndModule.first;
assert sdk != null;
PyConsoleOptions.PyConsoleSettings settingsProvider = PyConsoleOptions.getInstance(project).getPythonConsoleSettings();
PathMapper pathMapper = PydevConsoleRunner.getPathMapper(project, sdk, settingsProvider);
String[] setupFragment;
Collection<String> pythonPath = PythonCommandLineState.collectPythonPath(module, settingsProvider.shouldAddContentRoots(), settingsProvider.shouldAddSourceRoots());
if (pathMapper != null) {
pythonPath = pathMapper.convertToRemote(pythonPath);
}
String customStartScript = settingsProvider.getCustomStartScript();
if (customStartScript.trim().length() > 0) {
customStartScript = "\n" + customStartScript;
}
String workingDir = settingsProvider.getWorkingDirectory();
if (StringUtil.isEmpty(workingDir)) {
if (module != null && ModuleRootManager.getInstance(module).getContentRoots().length > 0) {
workingDir = ModuleRootManager.getInstance(module).getContentRoots()[0].getPath();
} else {
if (ModuleManager.getInstance(project).getModules().length > 0) {
VirtualFile[] roots = ModuleRootManager.getInstance(ModuleManager.getInstance(project).getModules()[0]).getContentRoots();
if (roots.length > 0) {
workingDir = roots[0].getPath();
}
}
}
}
if (pathMapper != null && workingDir != null) {
workingDir = pathMapper.convertToRemote(workingDir);
}
String selfPathAppend = PydevConsoleRunner.constructPyPathAndWorkingDirCommand(pythonPath, workingDir, customStartScript);
BuildoutFacet facet = null;
if (module != null) {
facet = BuildoutFacet.getInstance(module);
}
if (facet != null) {
List<String> path = facet.getAdditionalPythonPath();
if (pathMapper != null) {
path = pathMapper.convertToRemote(path);
}
String prependStatement = facet.getPathPrependStatement(path);
setupFragment = new String[] { prependStatement, selfPathAppend };
} else {
setupFragment = new String[] { selfPathAppend };
}
Map<String, String> envs = Maps.newHashMap(settingsProvider.getEnvs());
putIPythonEnvFlag(project, envs);
Consumer<String> rerunAction = title -> {
PydevConsoleRunnerImpl runner = createConsoleRunner(project, module);
runner.setConsoleTitle(title);
runner.run();
};
return createConsoleRunner(project, sdk, workingDir, envs, PyConsoleType.PYTHON, settingsProvider, rerunAction, setupFragment);
}
Aggregations