fix python constraint derived from markers to better support pre-release versions of Python#879
Conversation
…ase versions of Python
Reviewer's GuideRefactor normalization and parsing of Python version markers to handle pre-release versions by appending '.dev0' for '>=' constraints lacking full precision, replacing tilde-based wildcards with '.*', and ensuring marker-based '>=' operations use the stable version. The test suite is updated throughout to align expectations with these behaviors. Class diagram for updated Python version marker normalizationclassDiagram
class Utils {
+normalize_python_version_markers()
}
class Parser {
+parse_single_constraint(op, version, is_marker_constraint)
}
Utils --> Parser: uses
%% Highlight changes
Utils : + Handles '>=X.Y' by appending '.dev0'
Utils : + Replaces '~X.Y' with 'X.Y.*' for '=='
Parser : + For marker-based '>=', uses stable version
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey there - I've reviewed your changes - here's some feedback:
- The new .stable conversion in parse_single_constraint only applies to '>=' — consider applying a similar stable adjustment for '<=' or '<' marker constraints to correctly handle upper bounds with pre-releases.
- It could be useful to add a test for explicit prerelease markers (e.g. '==3.14rc1') to verify whether parse_marker_version_constraint accepts or rejects them as intended.
- Consider extracting the '.dev0' bump logic into a shared helper to reduce duplication between normalize_python_version_markers and the parser.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new .stable conversion in parse_single_constraint only applies to '>=' — consider applying a similar stable adjustment for '<=' or '<' marker constraints to correctly handle upper bounds with pre-releases.
- It could be useful to add a test for explicit prerelease markers (e.g. '==3.14rc1') to verify whether parse_marker_version_constraint accepts or rejects them as intended.
- Consider extracting the '.dev0' bump logic into a shared helper to reduce duplication between normalize_python_version_markers and the parser.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
Discussion here Tldr the spec is unhelpful, insofar as there is a consensus it probably is that poetry's current behaviour is correct - but the change you are making is desirable and the spec ought to be changed However I see no such change has happened. |
|
Thanks for the link and the summary. I intended a more subtle change to only derive correct constraints from markers but the poetry-plugin-export failures in python-poetry/poetry#10515 seem to show that this is not possible because it results in inconsistencies. I may try another approach to fix the original issue. |
https://github.com/python-poetry/poetry/actions/runs/17171517004/job/48721759731?pr=10514 (failure in
tests/utils/test_isolated_build.py::test_isolated_env_install_discards_requirements_not_needed_by_envwith Python 3.14rc2) shows that our installer does not handle environments of Python pre-release versions well. A dependency with the markerpython_version == "3.14"is not installed because it is translated into a Python constraint>=3.14,<3.15, which does not allow Python 3.14rc2. With this PR the Python constraint is>=3.14.dev0,<3.15.Downstream tests are fixed in python-poetry/poetry#10515
Summary by Sourcery
Improve marker-to-constraint translation to properly support Python pre-release versions by introducing
.dev0bounds and wildcard expansions for partial-precision markersNew Features:
.dev0for lower boundsEnhancements:
==xand!=xtox.*and append.dev0to>=xbounds when precision is less than two segments>=constraints as stable versions in the version parser for correct handling of dev releasesTests:
.dev0-based version constraints and update existing expectations to match new wildcard and dev0 conventions