Skip to content

馃悰 fix(discovery): match relative interpreter paths with ".." - #158

Merged
gaborbernat merged 3 commits into
tox-dev:mainfrom
darrenhuai:fix/relative-path-dotdot
Oct 27, 2026
Merged

gaborbernat merged 3 commits into
tox-dev:mainfrom
darrenhuai:fix/relative-path-dotdot

Conversation

@darrenhuai

@darrenhuai darrenhuai commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

A relative interpreter path that steps up a directory, such as ../venv/bin/python, was found and queried, then rejected, so get_interpreter returned None and iter_interpreters yielded nothing. 馃悰 virtualenv -p ../venv/bin/python failed the same way, as did ./../x, a/../b, and the Windows spellings with \ or /. Once this merges those paths find their interpreter.

Discovery proposes each candidate path, and the interpreter info then checks it against the spec. The two spelled the same file differently: the proposer kept .. in the absolute path, while the check collapsed it, so the comparison never matched. The proposer collapses .. again, as it did before #28 rewrote it. Normalizing on the comparison side instead would also match, but the returned executable would keep the ... A base interpreter's executable would then stop equaling its system_executable, which costs an extra lookup and caches the .. spelling.

An absolute spec that contains .. already matched; the only visible change for it is that the returned executable is now normalized.

darrenhuai and others added 3 commits October 21, 2026 23:10
A relative spec that steps up a directory, such as ../venv/bin/python or
..\other\Scripts\python.exe, never matched. get_interpreter returned None and
iter_interpreters yielded nothing, even though the file exists and was
interrogated. virtualenv hands -p straight to get_interpreter, so
virtualenv -p ../venv/bin/python could not find the interpreter either.

_check_exe proposed the candidate as Path(path).absolute(), which drops "."
parts but keeps "..", while PythonInfo._satisfies_path compares the executable
with os.path.abspath(spec.path), which collapses them. The two strings never
agreed, and neither the is_abs shortcut nor the basename fallback applies to a
relative path. The proposer used os.path.abspath before the standalone rewrite
in tox-dev#28, and the existing relative-path test only used a path below the cwd.

_check_exe now returns os.path.abspath(path) again, so the proposed executable
is spelled the way the comparison expects. try_first_with entries are already
resolved and absolute specs are accepted on is_abs, so for them the only
change is that an absolute spec with ".." reports a normalized executable.
@gaborbernat gaborbernat added the bug Something isn't working label Oct 27, 2026
@gaborbernat gaborbernat changed the title fix(discovery): match relative interpreter paths that contain ".." 馃悰 fix(discovery): match relative interpreter paths with ".." Oct 27, 2026

@gaborbernat gaborbernat left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gaborbernat
gaborbernat merged commit 38a7454 into tox-dev:main Oct 27, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants