Skip to content

Fix the dead guard around base interpreter resolution in interpreter inspect - #3337

Open
qianeric-backup wants to merge 1 commit into
pex-tool:mainfrom
qianeric-backup:fix-interpreter-inspect-base
Open

qianeric-backup wants to merge 1 commit into
pex-tool:mainfrom
qianeric-backup:fix-interpreter-inspect-base

Conversation

@qianeric-backup

@qianeric-backup qianeric-backup commented Nov 28, 2026 •

Copy link
Copy Markdown

Problem

pex3 interpreter inspect resolves the base interpreter of a venv inside a try/except whose whole purpose is to survive a failure (the guard added for #3113), and then immediately does the same resolution again, unguarded:

try:
    interpreter_info["base_interpreter"] = interpreter.resolve_base_interpreter().binary
except PythonInterpreter.BaseInterpreterResolutionError as e:
    logger.warning("Failed to determine base interpreter for venv interpreter ...")
interpreter_info["base_interpreter"] = interpreter.resolve_base_interpreter().binary

The second assignment makes the guard dead code: the warning is logged and the command then fails anyway with the same error it just caught. On the success path the base interpreter is resolved twice, and each resolution spawns a subprocess.

Reproduced with a virtualenv created from a --copies base interpreter whose binary is then moved away (the venv still runs, but its base interpreter can no longer be found):

$ pex3 interpreter inspect -v --python <venv>
WARNING Failed to determine base interpreter for venv interpreter ...: ...
Error: ...
$ echo $?
1

No JSON is produced at all, so -v on a venv always fails when the base interpreter cannot be resolved, even though the only consumer of base_interpreter is treated as optional by the code above it.

Fix

Remove the duplicated assignment, leaving the guarded one. The key is simply absent when the base interpreter cannot be resolved, which is what the except branch already intends, and the success path resolves it once instead of twice.

Test

tests/integration/cli/commands/test_interpreter_inspect.py gains a case that builds such a venv and asserts that the inspect still succeeds with JSON output, that base_interpreter is simply absent from it, and that the warning is still logged. Without the fix it fails with a non-zero exit and empty stdout. The single resolution on the success path is visible in the call count rather than asserted in the test: resolve_base_interpreter() is called twice before the change and once after it.

Notes on the existing suite

The integration suite needs network access (uv sync --frozen, pip downloads, URL fetches), so the failures around it change from run to run on this machine: the same test can fail and then pass on an unchanged tree. Nothing in the changed code is reachable from those tests; the case above is the only one that covers this branch.

Release notes

CHANGES.md gains a ## 2.107.2 section and pex/version.py is bumped, following the convention of the previous release commit (#3329).

… inspect`

The base interpreter of a venv is resolved inside a try/except that logs a
warning on BaseInterpreterResolutionError (pex-tool#3113), and then resolved again right
after the except block without a guard. That second assignment makes the guard
dead code: the warning is logged and the command still fails with the error it
just caught, and no JSON is produced. On the success path it also resolves the
base interpreter twice, spawning a subprocess each time.

Drop the duplicated assignment so the guarded one is the only one.
@qianeric-backup
qianeric-backup marked this pull request as ready for review November 28, 2026 15:45
@jsirois

jsirois commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Thanks for the report and PR @qianeric-backup. Your PR description smacks of AI; so I want to make sure you saw the opening sentences here: https://github.com/pex-tool/pex/blob/main/CONTRIBUTING.md#contributing

That aside, there is a real test failure on Mac for you to address that is due to Mac's unique Framework Python builds not meeting your test assumptions. The other failure is being addressed in #3336 (which will likely stomp your version bump / CHANGELOG edit).

@jsirois

jsirois commented Dec 3, 2026

Copy link
Copy Markdown
Member

@qianeric-backup if the AI contribution criteria takes you out of the running, please let me know and I'll close this (or you can). Otherwise I'll close on Friday, December 11th if I've heard no response.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants