Repository navigation
🐛 fix(discovery): let a relative path beat try_first_with - #261
Open
darrenhuai wants to merge 2 commits into
Open
darrenhuai wants to merge 2 commits into
darrenhuai wants to merge 2 commits into
Conversation
A spec like venv/bin/python can only be satisfied by that exact file, but it was probed after the try_first_with entries. When a hint resolved to the same file (a symlinked venv on POSIX, a different case on Windows) the spec path was skipped as already tested, and when a hint shared its base interpreter (the base itself or a sibling venv) the spec's own venv was skipped once the hint failed the path check. Discovery then returned None. Probe a spec path that has a directory part before the hints. Absolute paths and bare names behave as before.
A hint with the exact spec path already worked. What failed was the same file reached another way: venv/bin/python3 next to venv/bin/python on POSIX, or a different case on Windows.
This branch has not been deployed
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.
get_interpretercan't find an interpreter given as a relative path whentry_first_withholds a hint for the same install. On Windows, in a folder with two uv-made 3.12 environments,venv-aandvenv-b, I asked currentmainforvenv-b\Scripts\python.exewith different hints (results printed relative to the folder):It isn't Windows-only. In WSL, with two
python3 -m venvenvironments on the system 3.12,mainreturnsNonefromget_interpreterand[]fromiter_interpretersforvenv-b/bin/pythonwhen the hint isvenv-a/bin/python,venv-b/bin/python3or/usr/bin/python3. (On Windows,iter_interpretersstill lists venv-b for the sibling and base hints.) A hint with the exact spec path works on both.virtualenv 21.15.6 with python-discovery 1.9.5 agrees:
-p venv-b\Scripts\python.exeworks, and adding--try-first-withwith venv-a's python fails withRuntimeError: failed to find interpreter for Builtin discover of python_spec='venv-b\\Scripts\\python.exe'. With this branch on the same virtualenv, the--try-first-withrun creates the environment.A spec with a directory part can only match
abspath(spec.path), but_propose_explicitprobed the hints first, and one of two dedups then hid the spec path._check_exeskips a path that resolves to one already tested (a POSIX venv symlinked to its base, or the same file in another case on Windows)._find_interpreterskips a candidate whosesystem_executablewas already rejected, so a failed hint on the same base drops the spec's own venv._propose_explicitnow probes a spec path with a directory part before the hints. Nothing else can satisfy that spec, so the order change can't pick a different interpreter. Absolute paths still return early (pypa/virtualenv#2921 added that so a hint can't override an absolute path) and bare names keep their order.The new test is a relative twin of
test_discovery_absolute_path_with_try_first. It checksget_interpreteranditer_interpreterswith a sibling venv, the base interpreter and, on Windows, an upper-case spelling of the path as the hint. All three fail onmainand pass here on Windows with 3.14, and the sibling and base cases do the same in WSL with 3.12 and 3.14. I also updated thedocs/explanation.rstflowchart to the new order.