Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

esafak
Copy link
Contributor

@esafak esafak commented Aug 1, 2025

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 #2659, closes #2725

  • ran the linter to address style issues (tox -e fix)
  • wrote descriptive pull request text
  • ensured there are test(s) validating the fix
  • added news fragment in docs/changelog folder
  • updated/extended the documentation

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]>
@gaborbernat gaborbernat marked this pull request as draft August 1, 2025 14:32
google-labs-jules bot and others added 4 commits August 1, 2025 14:52
…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 gaborbernat marked this pull request as ready for review August 1, 2025 16:11
@gaborbernat gaborbernat enabled auto-merge (squash) August 1, 2025 16:11
@esafak
Copy link
Contributor Author

esafak commented Aug 1, 2025

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.

@gaborbernat gaborbernat merged commit f264539 into pypa:main Aug 1, 2025
120 of 122 checks passed
@esafak esafak deleted the fix/2725-try-first-with-absolute-path branch August 1, 2025 16:42
@ArcticLampyrid
Copy link

I’d like to know, if you only provide --try-first-with without specifying any --python parameter, what would you ideally expect to happen (I don’t mean the current implementation)? This used to be a workaround for #2285, and it is currently being adopted by Poetry. But this PR has broken it.

@gaborbernat
Copy link
Contributor

I’d like to know, if you only provide --try-first-with without specifying any --python

That's correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants