diff -Nru dput-1.0.3ubuntu1/debian/changelog dput-1.0.3ubuntu1.1/debian/changelog --- dput-1.0.3ubuntu1/debian/changelog 2019-04-22 12:31:01.000000000 +0200 +++ dput-1.0.3ubuntu1.1/debian/changelog 2023-06-29 16:58:12.000000000 +0200 @@ -1,3 +1,9 @@ +dput (1.0.3ubuntu1.1) focal; urgency=medium + + * Make versions with Ubuntu suffixes compliant with PEP 440 (LP: #1991606) + + -- Benjamin Drung Thu, 29 Jun 2023 16:58:12 +0200 + dput (1.0.3ubuntu1) eoan; urgency=medium [ Julian Andres Klode ] diff -Nru dput-1.0.3ubuntu1/setup.py dput-1.0.3ubuntu1.1/setup.py --- dput-1.0.3ubuntu1/setup.py 2019-04-22 12:31:01.000000000 +0200 +++ dput-1.0.3ubuntu1.1/setup.py 2023-06-29 16:58:04.000000000 +0200 @@ -11,6 +11,7 @@ import os import os.path import pydoc +import re import unittest import debian.changelog @@ -21,6 +22,22 @@ setup, ) + +def make_pep440_compliant(version: str) -> str: + """Convert the version into a PEP440 compliant version.""" + public_version_re = re.compile( + r"^([0-9][0-9.]*(?:(?:a|b|rc|.post|.dev)[0-9]+)*)\+?" + ) + _, public, local = public_version_re.split(version, maxsplit=1) + if not local: + return version + sanitized_local = re.sub("[+~]+", ".", local).strip(".") + pep440_version = f"{public}+{sanitized_local}" + assert re.match( + "^[a-zA-Z0-9.]+$", sanitized_local + ), f"'{pep440_version}' not PEP440 compliant" + return pep440_version + setup_dir = os.path.dirname(__file__) @@ -55,7 +72,7 @@ setup_kwargs = dict( name=changelog.package, - version=str(changelog.version), + version=make_pep440_compliant(str(changelog.version)), packages=find_packages(exclude=["test"]), # Setuptools metadata.