IDEA-CR-46638: PY-34574 Add content and source roots of module and its dependencies to PYTHONPATH for managed servers

(cherry picked from commit 929b60044214484c79ed2cd32e6ea7c1a9220b73)

GitOrigin-RevId: 52d13161ed691e4d8b1eeff4b935b2744bc9c35a
This commit is contained in:
Alexander Koshevoy
2019-04-28 19:22:31 +03:00
committed by intellij-monorepo-bot
parent 4b3f93b9bc
commit 9f9596a1e5
@@ -219,7 +219,8 @@ public abstract class PythonCommandLineState extends CommandLineState {
ProcessHandler processHandler = processStarter.start(myConfig, commandLine);
// attach extensions
PythonRunConfigurationExtensionsManager.Companion.getInstance().attachExtensionsToProcess(myConfig, processHandler, getRunnerSettings());
PythonRunConfigurationExtensionsManager.Companion.getInstance()
.attachExtensionsToProcess(myConfig, processHandler, getRunnerSettings());
return processHandler;
}
@@ -400,19 +401,34 @@ public abstract class PythonCommandLineState extends CommandLineState {
PythonSdkFlavor.setupEncodingEnvs(envs, charset);
}
private static void buildPythonPath(Project project, GeneralCommandLine commandLine, PythonRunParams config, boolean isDebug) {
Sdk pythonSdk = PythonSdkType.findSdkByPath(config.getSdkHome());
public static void buildPythonPath(@NotNull Project project,
@NotNull GeneralCommandLine commandLine,
@NotNull PythonRunParams config,
boolean isDebug) {
Module module = getModule(project, config);
buildPythonPath(module, commandLine, config.getSdkHome(), config.isPassParentEnvs(), config.shouldAddContentRoots(),
config.shouldAddSourceRoots(), isDebug);
}
public static void buildPythonPath(@Nullable Module module,
@NotNull GeneralCommandLine commandLine,
@Nullable String sdkHome,
boolean passParentEnvs,
boolean shouldAddContentRoots,
boolean shouldAddSourceRoots,
boolean isDebug) {
Sdk pythonSdk = PythonSdkType.findSdkByPath(sdkHome);
if (pythonSdk != null) {
List<String> pathList = Lists.newArrayList();
pathList.addAll(getAddedPaths(pythonSdk));
pathList.addAll(collectPythonPath(project, config, isDebug));
initPythonPath(commandLine, config.isPassParentEnvs(), pathList, config.getSdkHome());
pathList.addAll(collectPythonPath(module, sdkHome, shouldAddContentRoots, shouldAddSourceRoots, isDebug));
initPythonPath(commandLine, passParentEnvs, pathList, sdkHome);
}
}
public static void initPythonPath(GeneralCommandLine commandLine,
public static void initPythonPath(@NotNull GeneralCommandLine commandLine,
boolean passParentEnvs,
List<String> pathList,
@NotNull List<String> pathList,
final String interpreterPath) {
final PythonSdkFlavor flavor = PythonSdkFlavor.getFlavor(interpreterPath);
if (flavor != null) {
@@ -423,7 +439,8 @@ public abstract class PythonCommandLineState extends CommandLineState {
}
}
public static List<String> getAddedPaths(Sdk pythonSdk) {
@NotNull
public static List<String> getAddedPaths(@NotNull Sdk pythonSdk) {
List<String> pathList = new ArrayList<>();
final SdkAdditionalData sdkAdditionalData = pythonSdk.getSdkAdditionalData();
if (sdkAdditionalData instanceof PythonSdkAdditionalData) {
@@ -462,10 +479,18 @@ public abstract class PythonCommandLineState extends CommandLineState {
@VisibleForTesting
public static Collection<String> collectPythonPath(Project project, PythonRunParams config, boolean isDebug) {
final Module module = getModule(project, config);
final HashSet<String> pythonPath =
Sets.newLinkedHashSet(collectPythonPath(module, config.shouldAddContentRoots(), config.shouldAddSourceRoots()));
return collectPythonPath(module, config.getSdkHome(), config.shouldAddContentRoots(), config.shouldAddSourceRoots(), isDebug);
}
if (isDebug && PythonSdkFlavor.getFlavor(config.getSdkHome()) instanceof JythonSdkFlavor) {
@NotNull
public static Collection<String> collectPythonPath(@Nullable Module module,
@Nullable String sdkHome,
boolean shouldAddContentRoots,
boolean shouldAddSourceRoots,
boolean isDebug) {
final HashSet<String> pythonPath = Sets.newLinkedHashSet(collectPythonPath(module, shouldAddContentRoots, shouldAddSourceRoots));
if (isDebug && PythonSdkFlavor.getFlavor(sdkHome) instanceof JythonSdkFlavor) {
//that fixes Jython problem changing sys.argv on execfile, see PY-8164
pythonPath.add(PythonHelpersLocator.getHelperPath("pycharm"));
pythonPath.add(PythonHelpersLocator.getHelperPath("pydev"));