diff -Nru distro-info-0.23ubuntu1/debian/changelog distro-info-0.23ubuntu1.1/debian/changelog --- distro-info-0.23ubuntu1/debian/changelog 2020-02-13 21:10:55.000000000 +0100 +++ distro-info-0.23ubuntu1.1/debian/changelog 2023-04-25 15:57:38.000000000 +0200 @@ -1,3 +1,10 @@ +distro-info (0.23ubuntu1.1) focal; urgency=medium + + * python: Use PEP440 compliant version in setup.py (LP: #1991606) + * Update tests to match old date adjustments in distro-info-data 0.46. + + -- Benjamin Drung Tue, 25 Apr 2023 15:57:38 +0200 + distro-info (0.23ubuntu1) focal; urgency=low * Merge from Debian unstable. Remaining changes: diff -Nru distro-info-0.23ubuntu1/python/distro_info_test/test_setup.py distro-info-0.23ubuntu1.1/python/distro_info_test/test_setup.py --- distro-info-0.23ubuntu1/python/distro_info_test/test_setup.py 1970-01-01 01:00:00.000000000 +0100 +++ distro-info-0.23ubuntu1.1/python/distro_info_test/test_setup.py 2023-04-25 15:42:29.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-0.23ubuntu1/python/setup.py distro-info-0.23ubuntu1.1/python/setup.py --- distro-info-0.23ubuntu1/python/setup.py 2020-01-09 10:12:41.000000000 +0100 +++ distro-info-0.23ubuntu1.1/python/setup.py 2023-04-25 15:56:59.000000000 +0200 @@ -26,10 +26,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", diff -Nru distro-info-0.23ubuntu1/test-ubuntu-distro-info distro-info-0.23ubuntu1.1/test-ubuntu-distro-info --- distro-info-0.23ubuntu1/test-ubuntu-distro-info 2020-01-09 10:12:41.000000000 +0100 +++ distro-info-0.23ubuntu1.1/test-ubuntu-distro-info 2023-04-25 15:57:37.000000000 +0200 @@ -117,9 +117,9 @@ success "--date=2011-01-10 --fullname --lts --days=eol" \ 'Ubuntu 10.04 LTS "Lucid Lynx" 850' success "--date=2011-01-10 --fullname --lts -yeol-server" \ - 'Ubuntu 10.04 LTS "Lucid Lynx" 1570' + 'Ubuntu 10.04 LTS "Lucid Lynx" 1571' success "--date=2011-01-10 --fullname --lts --days=eol-server" \ - 'Ubuntu 10.04 LTS "Lucid Lynx" 1570' + 'Ubuntu 10.04 LTS "Lucid Lynx" 1571' } testRelease() { @@ -141,9 +141,9 @@ success "--date=2011-01-10 --lts --release -yeol" \ "10.04 LTS 850" success "--date=2011-01-10 --lts --release --days=eol-server" \ - "10.04 LTS 1570" + "10.04 LTS 1571" success "--date=2011-01-10 --lts --release -yeol-server" \ - "10.04 LTS 1570" + "10.04 LTS 1571" success "--date=2011-01-10 -r --stable" "10.10" } @@ -272,10 +272,10 @@ success "--date=$date --lts --days=eol -f" "Ubuntu 10.04 LTS \"Lucid Lynx\" 1105" success "--date=$date --lts --days=eol -r" "10.04 LTS 1105" - success "--date=$date --lts --days=eol-server" "1825" - success "--date=$date --lts --days=eol-server -c" "lucid 1825" - success "--date=$date --lts --days=eol-server -f" "Ubuntu 10.04 LTS \"Lucid Lynx\" 1825" - success "--date=$date --lts --days=eol-server -r" "10.04 LTS 1825" + success "--date=$date --lts --days=eol-server" "1826" + success "--date=$date --lts --days=eol-server -c" "lucid 1826" + success "--date=$date --lts --days=eol-server -f" "Ubuntu 10.04 LTS \"Lucid Lynx\" 1826" + success "--date=$date --lts --days=eol-server -r" "10.04 LTS 1826" # date precise released date=2012-04-26 @@ -297,15 +297,15 @@ success "--date=$date --lts --days -f" "Ubuntu 12.04 LTS \"Precise Pangolin\" 0" success "--date=$date --lts --days -r" "12.04 LTS 0" - success "--date=$date --lts --days=eol" "1826" - success "--date=$date --lts --days=eol -c" "precise 1826" - success "--date=$date --lts --days=eol -f" "Ubuntu 12.04 LTS \"Precise Pangolin\" 1826" - success "--date=$date --lts --days=eol -r" "12.04 LTS 1826" - - success "--date=$date --lts --days=eol-server" "1826" - success "--date=$date --lts --days=eol-server -c" "precise 1826" - success "--date=$date --lts --days=eol-server -f" "Ubuntu 12.04 LTS \"Precise Pangolin\" 1826" - success "--date=$date --lts --days=eol-server -r" "12.04 LTS 1826" + success "--date=$date --lts --days=eol" "1828" + success "--date=$date --lts --days=eol -c" "precise 1828" + success "--date=$date --lts --days=eol -f" "Ubuntu 12.04 LTS \"Precise Pangolin\" 1828" + success "--date=$date --lts --days=eol -r" "12.04 LTS 1828" + + success "--date=$date --lts --days=eol-server" "1828" + success "--date=$date --lts --days=eol-server -c" "precise 1828" + success "--date=$date --lts --days=eol-server -f" "Ubuntu 12.04 LTS \"Precise Pangolin\" 1828" + success "--date=$date --lts --days=eol-server -r" "12.04 LTS 1828" # day before raring was released date=2013-04-24