Compare commits

...
Author SHA1 Message Date
l0ng-ai 566631b6b8 fix(debugger): debug Python with a Windows venv interpreter given by its path
A Python run configuration whose command is a Windows path
(C:\…\.venv\Scripts\python.exe) was not recognised as an interpreter:
the path was only split at '/', so debugpy got a bare `python` from PATH
and the whole path as the module to run. When PATH has no usable
python, the launcher debugpy asks the IDE to start never connects
("Timed out waiting for launcher to connect"). Command names now split
at both separators, and a venv tool given by a backslash path debugs
with the python.exe next to it.

Fixes #3907
2026-11-17 20:28:21 +08:00
2 changed files with 24 additions and 6 deletions

No files matched your search

@@ -176,6 +176,24 @@ describe("run config → launch config", () => {
expect(extra(uv)).toMatchObject({ python: ["uv", "run", "python"], debugLauncherPython: "python" });
});
it("debugpy: a Windows venv interpreter or tool path debugs with that interpreter", () => {
usePlatform.setState({ os: "windows" });
const venv = "C:\\work\\app\\.venv\\Scripts\\";
const script = launchConfigFor(
rc({ kind: "python", command: `${venv}python.exe`, args: ["main.py"], debugAdapter: "debugpy" }),
"C:/work/app",
)!;
expect(extra(script).python).toBe(`${venv}python.exe`);
expect(extra(script).module).toBeUndefined();
expect(script.program).toBe("C:/work/app/main.py");
const pytest = launchConfigFor(
rc({ kind: "pytest", command: `${venv}pytest.exe`, args: ["-x"], debugAdapter: "debugpy" }),
"C:/work/app",
)!;
expect(extra(pytest)).toMatchObject({ module: "pytest", python: `${venv}python.exe` });
});
it("js-debug: npm scripts run through the package manager, node scripts directly", () => {
const npm = launchConfigFor(
rc({ kind: "npm", command: "pnpm", args: ["run", "dev"], cwd: "web", debugAdapter: "js-debug" }),
+6 -6
View File
@@ -76,7 +76,7 @@ function cargoLaunch(rc: RunConfig, cwd: string, adapter: string): LaunchConfig
};
}
const PYTHON_NAME = /^python[\d.]*(\.exe)?$/;
const PYTHON_NAME = /^python[\d.]*(\.exe)?$/i;
/** `python` on Windows (`python3` is at most a Store alias there, and venvs have no `python3.exe`), `python3` elsewhere. */
function systemPython(): string {
@@ -85,10 +85,10 @@ function systemPython(): string {
function pythonFor(rc: RunConfig, cwd: string): string {
const cmd = rc.command;
const name = cmd.split("/").pop() ?? cmd;
if (PYTHON_NAME.test(name)) return resolveCommand(cmd, cwd);
// A venv tool such as `.venv/bin/pytest`: use the interpreter next to it.
if (cmd.includes("/")) return resolveCommand(cmd.slice(0, cmd.lastIndexOf("/") + 1) + "python", cwd);
if (PYTHON_NAME.test(commandName(cmd))) return resolveCommand(cmd, cwd);
// A venv tool such as `.venv/bin/pytest` or `.venv\Scripts\pytest.exe`: use the interpreter next to it.
const dir = cmd.slice(0, Math.max(cmd.lastIndexOf("/"), cmd.lastIndexOf("\\")) + 1);
if (dir) return resolveCommand(dir + (hostOs() === "windows" ? "python.exe" : "python"), cwd);
return systemPython();
}
@@ -107,7 +107,7 @@ function debugpyLaunch(rc: RunConfig, cwd: string): LaunchConfig {
subProcess: dbg.python.attachSubprocess,
};
if (dbg.python.gevent) extra.gevent = true;
const name = (rc.command.split("/").pop() ?? rc.command).replace(/\.exe$/, "");
const name = commandName(rc.command);
let args = rc.args;
let tool: string | null = PYTHON_NAME.test(name) ? null : name;
if (PYTHON_RUNNERS.has(name) && args[0] === "run" && args[1]) {