Skip to content
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

version: fix normalize_version() according to PEP440 #344

Merged
merged 2 commits into from
May 10, 2022

Conversation

radoering
Copy link
Member

Resolves: python-poetry/poetry#5534

  • Added tests for changed code.
  • Updated documentation for changed code.

normalize_version() seems quite buggy supposing that it should do normalizations according to PEP 440. This PR fixes this method and adds tests derived from PEP 440 examples.

Since I wasn't sure if the to_string(short=False) method has some other usage (seems to be more semver than PEP440), I introduced a new property norm_string.

@abn
Copy link
Member

abn commented May 4, 2022

My 2c, I would say we return PEP440 compliant string when short is true rather than introducing another property. I'd like to avoid adding more cognitive load here and standardise one way.

@radoering
Copy link
Member Author

That was my first thought, too. But it seemed a bit confusing later.

It would be a bit weird especially for ReleaseTag because there is a shorten() and an expand() method. At the moment each long name has its short name (rev <-> r, post <-> -). But for PEP440 normalization rev as well as post are normalized to post. So if you call shorten() and expand() on rev you don't get rev back if we make the proposed change. That may be a bit confusing and even increase the cognitive load.

I'm not sure whether the two different variants (short and long) are useful at all. I tend to say that to_string() should always return a normalized version string (no short parameter). If that would be too much a breaking change, I'd say it may be better to introduce norm_string and maybe deprecate to_string().

Further, I'm not happy with short being a bad parameter name for normalized.

src/poetry/core/version/pep440/version.py Outdated Show resolved Hide resolved
tests/utils/test_helpers.py Show resolved Hide resolved
@abn abn mentioned this pull request May 8, 2022
Copy link
Member

@abn abn left a comment

Choose a reason for hiding this comment

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

Very minor comment. Otherwise lgtm.

src/poetry/core/version/pep440/segments.py Outdated Show resolved Hide resolved
@sonarcloud
Copy link

sonarcloud bot commented May 10, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
1.6% 1.6% Duplication

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

Successfully merging this pull request may close these issues.

Build artifacts omit period from .dev segment (1.2.0b1)
2 participants