fix(debugpy): auto-detect active venv, add --python override#20
fix(debugpy): auto-detect active venv, add --python override#20
Conversation
`dap debug script.py` previously always spawned `python3` from PATH,
ignoring the activated virtualenv. This caused wrong-interpreter errors
(and missing imports like `debugpy` itself) when users had a venv
active.
- CLI resolves `$VIRTUAL_ENV/bin/python{3,}` at invocation time (the
daemon's env may be stale), plumbed via new `DebugArgs.Python` field.
- New `--python` flag overrides auto-detection for conda/pyenv/shims.
- `debugpyBackend` gains `Python` field; `Spawn` honors it.
- Unit tests for `ResolveVenvPython` + `debugpyBackend.Python` wiring.
- E2E tests: explicit `--python`, bogus `--python` fails cleanly,
`VIRTUAL_ENV` auto-detection end-to-end.
- Docs: venv/`--python` note in installing-debuggers.md.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Review Summary by QodoAuto-detect active venv Python and add --python override flag
WalkthroughsDescription• Auto-detect active virtualenv's Python interpreter via $VIRTUAL_ENV • Add --python CLI flag to override interpreter selection • Pass resolved Python path from CLI to daemon via DebugArgs.Python • Wire debugpyBackend.Python field to Spawn() method • Comprehensive unit and E2E tests for venv detection and explicit override Diagramflowchart LR
CLI["CLI: dap debug script.py"]
ResolveVenv["ResolveVenvPython()"]
PythonFlag["--python flag"]
DebugArgs["DebugArgs.Python"]
Daemon["Daemon.handleDebug()"]
Backend["debugpyBackend.Python"]
Spawn["Spawn() uses configured Python"]
CLI -->|checks $VIRTUAL_ENV| ResolveVenv
PythonFlag -->|overrides| DebugArgs
ResolveVenv -->|fallback| DebugArgs
DebugArgs -->|plumbs to daemon| Daemon
Daemon -->|sets field| Backend
Backend -->|exec.Command| Spawn
File Changes1. backend.go
|
Code Review by Qodo
1.
|
…xport field
- ResolveVenvPython now picks the correct layout per-OS: Scripts\python.exe
on Windows, bin/python{3,} on POSIX. Returns absolute paths.
- New ResolvePythonFlag resolves --python at the CLI layer: bare names go
through exec.LookPath (caller's PATH, not the daemon's), paths are made
absolute. Unknown/missing binaries fail with a clear CLI error instead
of silently falling through to the daemon.
- Rename debugpyBackend.Python -> debugpyBackend.python (unexported struct
shouldn't expose fields).
- Unit tests for ResolvePythonFlag (abs, relative, bare-name, nonexistent,
bare-name-not-found) and OS-aware venv tests.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Pre-existing race: stopSession() sets d.client = nil while readLoop dereferences d.client.ReadMessage() on the next iteration — panics with SIGSEGV in CI under load. Pin the client to a local at loop start via getClient(); Close() on the client will surface as a read error and the loop exits cleanly. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Summary
dap debug script.pysilently ignored the active virtualenv and always used systempython3, causing wrong-interpreter errors (e.g. missingdebugpyin the venv, Python version mismatch).$VIRTUAL_ENV/bin/python{3,}at invocation and passes the path to the daemon (whose env may be stale).--pythonflag overrides auto-detection for conda / pyenv shims / non-standard layouts.Changes
debugpyBackendgains aPythonfield;Spawnhonors it (falls back topython3when unset).DebugArgs.Pythonplumbs the CLI-resolved interpreter to the daemon.ResolveVenvPython()helper reads$VIRTUAL_ENVat CLI call time.references/installing-debuggers.md.Test plan
ResolveVenvPython— no env, missing binary, python3, fallback to python, prefers python3.debugpyBackend.Spawnuses configuredPythonbinary.--pythonhappy path lands at breakpoint.--pythonfails cleanly (no silent fallback).VIRTUAL_ENVauto-detection picks up stub venv python (proves auto-detect wins over system).go test ./...) passes.🤖 Generated with Claude Code