From 4ef95291ca539cd7d058e64e165d9154fdaada55 Mon Sep 17 00:00:00 2001 From: Maxim Popov Date: Thu, 27 Aug 2026 20:43:32 +0000 Subject: [PATCH] PY-91831 [debugger]: keep the IDE's PYTHONPATH entries under debugpy The debugpy launch configuration is assembled outside PythonCommandLineState.startProcess, and it applied the run configuration's own environment variables after the entries the IDE contributes. A PYTHONPATH typed into Environment variables therefore replaced the content roots, the source roots and the interpreter's added paths rather than extending them, and the debuggee failed to import a project module. Run mode and the pydevd backend order the two the other way round, in PythonCommandLineState.initEnvironment. Contribute those entries after the configuration's own variables, through PythonEnvUtil.initPythonPath, so the typed value keeps its precedence and the roots are appended to it. This also preserves a PYTHONPATH coming from an env file, which the previous helper dropped by seeding its merge from getEnvs() alone, and passes isPassParentEnvs instead of an unconditional true so the system PYTHONPATH is not folded in when the debuggee does not inherit the parent environment. The PythonCommandLineState.buildPythonPath(configuration, passParentEnvs) overload was added for this single caller and now has none, so it is removed instead of reshaped; the composition lives next to the launcher that needs it. IJ-MR-220448 Merge-request: IJ-MR-220658 Merged-by: Maxim Popov GitOrigin-RevId: b3c6145c73291ddf81c3c6a4479dee7572b16a45 --- .../python/run/PythonCommandLineState.java | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/python/src/com/jetbrains/python/run/PythonCommandLineState.java b/python/src/com/jetbrains/python/run/PythonCommandLineState.java index ba96c479dc3a..eed885ad21a3 100644 --- a/python/src/com/jetbrains/python/run/PythonCommandLineState.java +++ b/python/src/com/jetbrains/python/run/PythonCommandLineState.java @@ -110,7 +110,6 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; @@ -908,24 +907,6 @@ public abstract class PythonCommandLineState extends CommandLineState { } } - @ApiStatus.Internal - public static @NotNull Map buildPythonPath(@NotNull AbstractPythonRunConfiguration configuration, - boolean passParentEnvs) { - Map envs = new HashMap<>(configuration.getEnvs()); - Module module = configuration.getModule(); - Sdk sdk = configuration.getSdk(); - - if (sdk != null) { - List pathList = new ArrayList<>(); - pathList.addAll(getAddedPaths(sdk)); - pathList.addAll(collectPythonPath(module, configuration.shouldAddContentRoots(), configuration.shouldAddSourceRoots())); - PythonEnvUtil.initPythonPath(envs, passParentEnvs, pathList); - } - - return envs; - } - - @ApiStatus.Internal public static void buildPythonPath(@NotNull Project project, @Nullable Module module,