fix: --try-first-with was overriding an absolute --python path#2921
Merged
gaborbernat merged 5 commits intopypa:mainfrom Aug 1, 2025
Merged
fix: --try-first-with was overriding an absolute --python path#2921gaborbernat merged 5 commits intopypa:mainfrom
--try-first-with was overriding an absolute --python path#2921gaborbernat merged 5 commits intopypa:mainfrom
Conversation
When you use `--python` with an absolute path, it should be a strict requirement. However, I noticed that if you also used `--try-first-with`, an interpreter from `--try-first-with` could be selected even if it didn't match the absolute path from `--python`. To fix this, I adjusted the logic in the `satisfies` method of the `PythonInfo` class. Now, if a `PythonSpec` contains an absolute path, any candidate interpreter whose executable path doesn't exactly match is immediately rejected. I've also added a regression test to make sure this doesn't happen again. Finally, I updated the documentation to clarify how `--python` and `--try-first-with` are intended to work together. Essentially, `--python` sets the rule, and `--try-first-with` provides hints that are only used if they follow that rule. Closes pypa#2659, closes pypa#2725 Signed-off-by: Emre Şafak <[email protected]>
…te `--python` path. When you use `--python` with an absolute path, it should be a strict requirement. However, I noticed that if you also used `--try-first-with`, an interpreter from `--try-first-with` could be selected even if it didn't match the absolute path from `--python`. To fix this, I've adjusted the logic in the `propose_interpreters` function. Now, if a `PythonSpec` contains an absolute path, only that path will be considered. I've also added a regression test to make sure this doesn't happen again. Finally, I've updated the documentation to clarify how `--python` and `--try-first-with` are intended to work together. Essentially, `--python` sets the rule, and `--try-first-with` provides hints that are only used if they follow that rule.
When `--python` is used with an absolute path, it should be treated as a strict requirement. Currently, if `--try-first-with` is also used, an interpreter from `--try-first-with` could be selected even if it didn't match the absolute path from `--python`. This commit corrects the logic in the `propose_interpreters` function. If a `PythonSpec` contains an absolute path, only that path is considered. A regression test has been added to verify this fix. The test is now platform-aware and creates real virtual environments to ensure it works correctly on all operating systems. Additionally, the documentation has been updated to clarify the intended interaction between `--python` and `--try-first-with`, explaining that `--python` sets the rule and `--try-first-with` provides hints that are only used if they satisfy that rule.
Signed-off-by: Emre Şafak <[email protected]>
Signed-off-by: Emre Şafak <[email protected]>
gaborbernat
approved these changes
Aug 1, 2025
Contributor
Author
|
It won't auto merge since a test was canceled, but that one passed before I edited some unrelated files so I'm confident it is ok. |
|
I’d like to know, if you only provide |
Contributor
That's correct. |
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.
When you use
--pythonwith an absolute path, it should be a strict requirement. However, I noticed that if you also used--try-first-with, an interpreter from--try-first-withcould be selected even if it didn't match the absolute path from--python.To fix this, I adjusted the logic in the
satisfiesmethod of thePythonInfoclass. Now, if aPythonSpeccontains an absolute path, any candidate interpreter whose executable path doesn't exactly match is immediately rejected.I've also added a regression test to make sure this doesn't happen again.
Finally, I updated the documentation to clarify how
--pythonand--try-first-withare intended to work together. Essentially,--pythonsets the rule, and--try-first-withprovides hints that are only used if they follow that rule.Closes #2659, closes #2725
tox -e fix)docs/changelogfolder