Skip to content

Commit

Permalink
Merge pull request #4434 from abravalheri/issue-3593
Browse files Browse the repository at this point in the history
Improve support for PEP 625 - bugfix for versions like '1.0-2'
  • Loading branch information
jaraco authored Jun 27, 2024
2 parents 2ddb4d4 + 63985e6 commit 9fa33a1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 2 additions & 0 deletions newsfragments/4434.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix distribution name normalisation (:pep:`625`) for valid versions that are
not canonical (e.g. ``1.0-2``).
22 changes: 19 additions & 3 deletions setuptools/_core_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from . import _normalization, _reqs
from .extern.packaging.markers import Marker
from .extern.packaging.requirements import Requirement
from .extern.packaging.utils import canonicalize_name
from .extern.packaging.utils import canonicalize_name, canonicalize_version
from .extern.packaging.version import Version
from .warnings import SetuptoolsDeprecationWarning

Expand Down Expand Up @@ -263,7 +263,23 @@ def _write_provides_extra(file, processed_extras, safe, unsafe):

# from pypa/distutils#244; needed only until that logic is always available
def get_fullname(self):
return _distribution_fullname(self.get_name(), self.get_version())


def _distribution_fullname(name: str, version: str) -> str:
"""
>>> _distribution_fullname('setup.tools', '1.0-2')
'setup_tools-1.0.post2'
>>> _distribution_fullname('setup-tools', '1.2post2')
'setup_tools-1.2.post2'
>>> _distribution_fullname('setup-tools', '1.0-r2')
'setup_tools-1.0.post2'
>>> _distribution_fullname('setup.tools', '1.0.post')
'setup_tools-1.0.post0'
>>> _distribution_fullname('setup.tools', '1.0+ubuntu-1')
'setup_tools-1.0+ubuntu.1'
"""
return "{}-{}".format(
canonicalize_name(self.get_name()).replace('-', '_'),
self.get_version(),
canonicalize_name(name).replace('-', '_'),
canonicalize_version(version, strip_trailing_zero=False),
)

0 comments on commit 9fa33a1

Please sign in to comment.