diff -Nru dput-1.1.3ubuntu2/debian/changelog dput-1.1.3ubuntu2.1/debian/changelog --- dput-1.1.3ubuntu2/debian/changelog 2023-02-16 22:38:56.000000000 +0100 +++ dput-1.1.3ubuntu2.1/debian/changelog 2023-07-01 01:49:41.000000000 +0200 @@ -1,3 +1,9 @@ +dput (1.1.3ubuntu2.1) lunar; urgency=medium + + * Make PEP 440 version conversion more robust for SRUs (LP: #1991606) + + -- Benjamin Drung Sat, 01 Jul 2023 01:49:41 +0200 + dput (1.1.3ubuntu2) lunar; urgency=medium * Make versions with Ubuntu suffixes compliant with PEP 440. diff -Nru dput-1.1.3ubuntu2/setup.py dput-1.1.3ubuntu2.1/setup.py --- dput-1.1.3ubuntu2/setup.py 2023-02-16 22:33:45.000000000 +0100 +++ dput-1.1.3ubuntu2.1/setup.py 2023-07-01 01:49:35.000000000 +0200 @@ -22,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__) @@ -40,11 +56,6 @@ (maintainer_name, maintainer_email) = email.utils.parseaddr( control_structure['maintainer']) -# According to PEP 440, an ubuntuX suffix is considered an invalid version -# Make the version compliant (e.g. 1.1.3ubuntu2 -> 1.1.3.post2) -if bool(re.match(r"([0-9]+(\.[0-9]+)+)ubuntu[0-9]+", str(changelog.version))): - changelog.version = str(changelog.version).replace("ubuntu", ".post") - copyright_file_path = os.path.join(setup_dir, "debian", "copyright") with open(copyright_file_path) as copyright_file: copyright_structure = debian.copyright.Copyright(copyright_file) @@ -61,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.