fix(doctor): use sys.executable for pip show in _pip_version#2
Merged
Merged
Conversation
The 'doctor' command failed on runners where the conda environment
only exposes 'python3' (not 'python') in PATH:
File '.../hust_ascend_manager/doctor.py', line 295, in _pip_version
rc, out, _ = _run(['python', '-m', 'pip', 'show', pkg])
FileNotFoundError: [Errno 2] No such file or directory: 'python'
This blocks 'hust-ascend-manager setup' (which calls doctor.collect_report)
on minimal Ascend images and CI runners. Hardcoding 'python' is fragile:
on Euleros / Ascend base images the venv only ships python3 binaries.
Fix: invoke the same Python interpreter that is running the manager
itself, via sys.executable. This is guaranteed to:
- exist (it is the running process)
- have pip available (we loaded from this env)
- be the canonical interpreter for the active env, regardless of
whether the user has 'python', 'python3', 'python3.11', etc. in PATH
- work inside conda envs, venvs, and containers without modification
No new imports needed: 'sys' is already imported at the top of
doctor.py. Sibling module 'runtime.py' already handles this concern
with an explicit ('python3', 'python') fallback list (line 38); using
sys.executable is more robust because it is the actual interpreter
that imported the package.
Verification:
- pytest tests/ -q: 66 passed
- _pip_version('pip') returns the expected version
- _pip_version('not-a-real-package') returns None (same as before)
Co-authored-by: Qoder Agent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix
hust-ascend-manager setup/doctorfailing on minimal Ascendruntimes where the conda env only exposes
python3(notpython).Root cause
In
src/hust_ascend_manager/doctor.py,_pip_versionwas hardcodingthe interpreter name:
On runners where the active env ships only
python3(typical ofEuleros/Ascend base images and minimal CI runners), this raises:
The traceback was observed in CI when
setupinvokesdoctor.collect_report()(seecli.py:140→setup.py:220→doctor.py:703→_pip_version).Fix
Replace the hardcoded
"python"withsys.executable. This isguaranteed to:
exists as a real path)
pipavailable in the same envregardless of whether
python,python3, orpython3.11is inPATH
No new imports needed (
sysis already imported at the top ofdoctor.py).Scope
Single-line change in
_pip_version. Sibling moduleruntime.pyalready handles the same concern with an explicit
("python3", "python")fallback list —sys.executableis themore robust version of that pattern.
Verification
pytest tests/ -q: 66 passed (no test changes needed — they mock_pip_versiondirectly)._pip_version("pip")returns the actual version(
'26.1.2'in the dev env)._pip_version("not-a-real-pkg")returnsNone(unchangedbehaviour on missing packages).
Related
This is the same class of issue that already exists in
runtime.py:38(for candidate in ("python3", "python")), butthe doctor path was missed. This PR only fixes the doctor path. The
runtime path can be unified with
sys.executablein a follow-upif desired.
Assisted-by: Qoder Agent