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

Fix crash if dependencies have prerelease requires-python versions #1112

Merged
merged 2 commits into from
Jun 3, 2022

Conversation

Hnasar
Copy link
Contributor

@Hnasar Hnasar commented Jun 2, 2022

Recently, coverage 6.4.1 listed its requirements with an alpha version of
python and this broke PDM's version parsing:

extras_require={
    'toml': ['tomli; python_full_version<="3.11.0a6"'],
},

Prerelease requires-python versions are valid, per these specifications:

Therefore this commit adds missing parsing support for {a|b|rc}[N]
pre-release specifiers which are used by python language releases:

This bug meant that projects that directly or indirectly depended on coverage
were unable to update pdm.lock using commands like update add lock and
install because pdm.models.versions.Version would raise:

pdm.exceptions.InvalidPyVersion: 3.11.0a6: Prereleases or postreleases are not supported for python version specifers.

Until this is fixed, projects can workaround this by depending on:

"coverage<6.4",
"coverage[toml]<6.4",

Fixes #1111

Recently, coverage 6.4.1 listed its requirements with an alpha version of
python and this broke PDM's version parsing:

    extras_require={
        'toml': ['tomli; python_full_version<="3.11.0a6"'],
    },

Prerelease `requires-python` versions *are* valid, per these specifications:

* https://peps.python.org/pep-0440/
* https://peps.python.org/pep-0621/#requires-python
* https://packaging.python.org/en/latest/specifications/core-metadata/#requires-python

Therefore this commit adds missing parsing support for `{a|b|rc}[N]`
pre-release specifiers which are used by python language releases:

* https://docs.python.org/3/faq/general.html#how-does-the-python-version-numbering-scheme-work

This bug meant that projects that directly or indirectly depended on coverage
were unable to update pdm.lock using commands like `update` `add` `lock` and
`install` because `pdm.models.versions.Version` would raise:

    pdm.exceptions.InvalidPyVersion: 3.11.0a6: Prereleases or postreleases are not supported for python version specifers.

Until this is fixed, projects can workaround this by depending on:

    "coverage<6.4",
    "coverage[toml]<6.4",

Fixes pdm-project#1111
@frostming
Copy link
Collaborator

frostming commented Jun 3, 2022

Thanks for doing this, mostly LGTM. Can you remove the workaround here since prereleases are now supported in the python specifier.

Since prereleases are now supported in python specifiers (in the
previous commit), we can remove the workaround (from commit 8e72609
for pdm-project#932) that converted a python prerelease version to a specifier
range.
@Hnasar
Copy link
Contributor Author

Hnasar commented Jun 3, 2022

@frostming Thank you for PDM! I removed the workaround entirely since the function is only used in a single place.

@codecov-commenter
Copy link

Codecov Report

Merging #1112 (a8bccfd) into main (23ab30b) will increase coverage by 0.03%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #1112      +/-   ##
==========================================
+ Coverage   84.30%   84.33%   +0.03%     
==========================================
  Files          74       74              
  Lines        6532     6577      +45     
  Branches     1355     1543     +188     
==========================================
+ Hits         5507     5547      +40     
- Misses        696      701       +5     
  Partials      329      329              
Flag Coverage Δ
unittests 84.09% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pdm/models/specifiers.py 79.64% <100.00%> (+1.36%) ⬆️
pdm/models/versions.py 94.17% <100.00%> (+2.74%) ⬆️
pdm/project/core.py 89.65% <100.00%> (ø)
pdm/installers/installers.py 78.65% <0.00%> (-3.04%) ⬇️
pdm/models/repositories.py 76.59% <0.00%> (-0.86%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 23ab30b...a8bccfd. Read the comment docs.

Copy link
Collaborator

@frostming frostming left a comment

Choose a reason for hiding this comment

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

Neat!

@frostming frostming merged commit 41598a6 into pdm-project:main Jun 3, 2022
@Hnasar Hnasar deleted the pre-release-versions branch June 3, 2022 15:35
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.

InvalidPyVersion raised when trying to add a coverage dependency
3 participants