-
Notifications
You must be signed in to change notification settings - Fork 254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(pep440): do not ignore post for inclusive ordering #379
base: main
Are you sure you want to change the base?
Conversation
cfdccfc
to
c4bb9bd
Compare
Kudos, SonarCloud Quality Gate passed! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that's completely correct yet. PEP440 says:
"Comparison and ordering of local versions considers each segment of the local version (divided by a .) separately. If a segment consists entirely of ASCII digits then that section should be considered an integer for comparison purposes and if a segment contains any ASCII letters then that segment is compared lexicographically with case insensitivity. When comparing a numeric and lexicographic segment, the numeric section always compares as greater than the lexicographic segment. Additionally a local version with a great number of segments will always compare as greater than a local version with fewer segments, as long as the shorter local version’s segments match the beginning of the longer local version’s segments exactly."
It seems that comparing local version segments is already prepared here:
poetry-core/src/poetry/core/version/pep440/version.py
Lines 108 to 125 in dfd1b39
_local: tuple[tuple[int, int | str], ...] | |
if self.local is None: | |
# Versions without a local segment should sort before those with one. | |
_local = ((NegativeInfinity(), ""),) | |
else: | |
# Versions with a local segment need that segment parsed to implement | |
# the sorting rules in PEP440. | |
# - Alpha numeric segments sort before numeric segments | |
# - Alpha numeric segments sort lexicographically | |
# - Numeric segments sort numerically | |
# - Shorter versions sort before longer versions when the prefixes | |
# match exactly | |
assert isinstance(self.local, tuple) | |
_local = tuple( | |
# We typecast strings that are integers so that they can be compared | |
(int(i), "") if str(i).isnumeric() else (NegativeInfinity(), i) | |
for i in self.local | |
) |
c4bb9bd
to
0416da4
Compare
@sourcery-ai review |
Reviewer's Guide by SourceryThis pull request fixes an issue where local label comparison was inconsistent with PEP 440. The fix ensures that post releases are not ignored when performing inclusive ordering comparisons. Class diagram showing changes to VersionRange classclassDiagram
class VersionRange {
-_min: Version
-_max: Version
-_include_min: bool
-_include_max: bool
+is_any(): bool
+is_simple(): bool
+is_inclusive(): bool
+is_exclusive(): bool
+allows(other: Version): bool
}
note for VersionRange "Added new properties is_inclusive and is_exclusive
Modified allows() method to handle post-releases correctly"
Flow diagram for version comparison logicflowchart TD
A[Start Version Comparison] --> B{Is minimum version set?}
B -->|No| E[Allow version]
B -->|Yes| C{Is exclusive comparison?}
C -->|No| E
C -->|Yes| D{Is other version a post-release<br>and min version not?}
D -->|Yes| F[Reject version]
D -->|No| E
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @abn - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
0416da4
to
1a3a7e9
Compare
Actually, I am not sure if this fixes anything regarding compliance with PEP 440. I even think this will be less compliant with PEP 440 than before. It feels like switching from one use case to another. According to PEP 440, local version labels are not allowed in constraints with If I understand correctly, this PR tries to make something like this work: However, to make this work, it breaks the use case where Honestly, the second use case feels more correct (i.e. more compliant) than the first one. On the other side, I understand that the first one might be the more common one (at least when neglecting private packages inside of companies). I think this change will be breaking for some users and make us less compliant with PEP 440. I feel like we should carefully weigh if it is worth it. Is there an open issue about this? The issue that is linked has already been resolved. |
0877107
to
2bff41a
Compare
2bff41a
to
1a61f52
Compare
When through the spec again, been a while. And I agree that the original changes I had is swapping one "interpretation" for another. I also agree that Taking all that into considering, I have gone ahead and repurposed this PR to only include the following:
As for what to do with
|
@sourcery-ai review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @abn - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Summary by Sourcery
Bug Fixes: