diff -Nru distro-info-1.1build1/debian/changelog distro-info-1.1ubuntu0.1/debian/changelog --- distro-info-1.1build1/debian/changelog 2022-03-23 14:50:40.000000000 +0100 +++ distro-info-1.1ubuntu0.1/debian/changelog 2023-04-25 15:30:42.000000000 +0200 @@ -1,3 +1,9 @@ +distro-info (1.1ubuntu0.1) jammy; urgency=medium + + * python: Use PEP440 compliant version in setup.py (LP: #1991606) + + -- Benjamin Drung Tue, 25 Apr 2023 15:30:42 +0200 + distro-info (1.1build1) jammy; urgency=medium * No-change rebuild for ppc64el baseline bump. diff -Nru distro-info-1.1build1/debian/control distro-info-1.1ubuntu0.1/debian/control --- distro-info-1.1build1/debian/control 2021-11-04 22:27:37.000000000 +0100 +++ distro-info-1.1ubuntu0.1/debian/control 2023-04-25 15:30:42.000000000 +0200 @@ -1,7 +1,8 @@ Source: distro-info Section: devel Priority: optional -Maintainer: Benjamin Drung +Maintainer: Ubuntu Developers +XSBC-Original-Maintainer: Benjamin Drung Uploaders: Stefano Rivera Build-Depends: debhelper-compat (= 13), dh-python, diff -Nru distro-info-1.1build1/python/distro_info_test/test_setup.py distro-info-1.1ubuntu0.1/python/distro_info_test/test_setup.py --- distro-info-1.1build1/python/distro_info_test/test_setup.py 1970-01-01 01:00:00.000000000 +0100 +++ distro-info-1.1ubuntu0.1/python/distro_info_test/test_setup.py 2023-04-25 15:30:05.000000000 +0200 @@ -0,0 +1,58 @@ +# Copyright (C) 2022, Benjamin Drung +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. + +"""Test functions in setup.py.""" + +import unittest +import unittest.mock + +from setup import make_pep440_compliant + + +class SetupTestCase(unittest.TestCase): + """Test functions in setup.py.""" + + def test_make_pep440_compliant_unchanged(self) -> None: + """Test make_pep440_compliant() with already correct version.""" + self.assertEqual(make_pep440_compliant("1.2"), "1.2") + + def test_make_pep440_compliant_debian_backport(self) -> None: + """Test make_pep440_compliant() with Debian backport version.""" + self.assertEqual(make_pep440_compliant("0.21~bpo9+1"), "0.21+bpo9.1") + + def test_make_pep440_compliant_debian_stable(self) -> None: + """Test make_pep440_compliant() with Debian stable update.""" + self.assertEqual(make_pep440_compliant("2.21.3+deb11u1"), "2.21.3+deb11u1") + + def test_make_pep440_compliant_debian_stable_backport(self) -> None: + """Test make_pep440_compliant() with Debian stable backport.""" + self.assertEqual(make_pep440_compliant("2.21.3+deb11u1~bpo10+1"), "2.21.3+deb11u1.bpo10.1") + + def test_make_pep440_compliant_tilde(self) -> None: + """Test make_pep440_compliant() with tilde in Debian version.""" + self.assertEqual(make_pep440_compliant("0.175~18.04.3"), "0.175+18.04.3") + + def test_make_pep440_compliant_ubuntu(self) -> None: + """Test make_pep440_compliant() with Ubuntu version.""" + self.assertEqual(make_pep440_compliant("1.1ubuntu1"), "1.1+ubuntu1") + + def test_make_pep440_compliant_ubuntu_backport(self) -> None: + """Test make_pep440_compliant() with Ubuntu backport version.""" + self.assertEqual( + make_pep440_compliant("2.22.1ubuntu1~bpo20.04.1"), "2.22.1+ubuntu1.bpo20.04.1" + ) + + def test_make_pep440_compliant_ubuntu_security(self) -> None: + """Test make_pep440_compliant() with Ubuntu security update.""" + self.assertEqual(make_pep440_compliant("2.17.12ubuntu1.1"), "2.17.12+ubuntu1.1") diff -Nru distro-info-1.1build1/python/setup.py distro-info-1.1ubuntu0.1/python/setup.py --- distro-info-1.1build1/python/setup.py 2021-11-04 22:27:37.000000000 +0100 +++ distro-info-1.1ubuntu0.1/python/setup.py 2023-04-25 15:30:05.000000000 +0200 @@ -24,10 +24,22 @@ return version +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 + + if __name__ == "__main__": setup( name="distro-info", - version=get_debian_version(), + version=make_pep440_compliant(get_debian_version()), py_modules=PY_MODULES, packages=PACKAGES, test_suite="distro_info_test",