use of com.intellij.util.PathMapper 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