diff --git a/newsfragments/4434.bugfix.rst b/newsfragments/4434.bugfix.rst new file mode 100644 index 0000000000..5eeb674297 --- /dev/null +++ b/newsfragments/4434.bugfix.rst @@ -0,0 +1,2 @@ +Fix distribution name normalisation (:pep:`625`) for valid versions that are +not canonical (e.g. ``1.0-2``). diff --git a/setuptools/_core_metadata.py b/setuptools/_core_metadata.py index f1de9c9ba6..45aae7d70b 100644 --- a/setuptools/_core_metadata.py +++ b/setuptools/_core_metadata.py @@ -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 @@ -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), )