From 565bdcbc65391bbbc1e595cb3c46cea91c14fc26 Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Aug 20 2024 01:45:12 +0000 Subject: Update check_bodhi_version to check for >= 6.0.0 This loses the logic for handling an exception if we're under 2.0 or bodhi-client isn't installed at all, but ehhh, that seems unnecessary. It's pretty unlikely anyone could manage to have < 2.0 at this point. Merges: https://pagure.io/fedpkg/pull-request/560 Signed-off-by: Adam Williamson --- diff --git a/fedpkg/cli.py b/fedpkg/cli.py index d27b8b1..d42f848 100644 --- a/fedpkg/cli.py +++ b/fedpkg/cli.py @@ -23,9 +23,14 @@ import textwrap from datetime import datetime # Use deprecated pkg_resources if importlib isn't available (python 3.6) try: - import importlib.metadata + from importlib.metadata import distribution except ImportError: - import pkg_resources + from pkg_resources import get_distribution as distribution +# Use deprecated pkg_resources if packaging library isn't available (python 3.6) +try: + from packaging.version import parse as parse_version +except ImportError: + from pkg_resources import parse_version from pyrpkg import rpkgError from pyrpkg.cli import cliClient import configparser @@ -94,16 +99,9 @@ require_testcases=%(require_testcases)s def check_bodhi_version(): # Use deprecated pkg_resources if importlib isn't available (python 3.6) - try: - try: - importlib.metadata.distribution('bodhi_client') - except importlib.metadata.PackageNotFoundError: - raise rpkgError('bodhi-client < 2.0 is not supported.') - except NameError: - try: - pkg_resources.get_distribution('bodhi_client') - except pkg_resources.DistributionNotFound: - raise rpkgError('bodhi-client < 2.0 is not supported.') + bodhi_version = distribution('bodhi-client').version + if parse_version(bodhi_version) < parse_version("6.0.0"): + raise rpkgError('bodhi-client < 6.0.0 is not supported.') class fedpkgClient(cliClient): diff --git a/test/test_cli.py b/test/test_cli.py index e2d82dc..d201e7f 100644 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -1604,34 +1604,15 @@ class TestRequestTestsRepo(CliTestCase): self.assertEqual(str(error), expected_error) -# Use deprecated pkg_resources if importlib isn't available (python 3.6) -try: - import importlib.metadata - - class TestCheckBodhiVersion(unittest.TestCase): - """Test check_bodhi_version""" - - @patch('importlib.metadata.distribution') - def test_no_2_x_version_installed(self, distribution): - distribution.side_effect = importlib.metadata.PackageNotFoundError - - self.assertRaisesRegex( - rpkgError, r'bodhi-client < 2\.0 is not supported\.', - check_bodhi_version) +class TestCheckBodhiVersion(unittest.TestCase): + """Test check_bodhi_version""" -except ImportError: - import pkg_resources - - class TestCheckBodhiVersion(unittest.TestCase): - """Test check_bodhi_version""" - - @patch('pkg_resources.get_distribution') - def test_no_2_x_version_installed(self, get_distribution): - get_distribution.side_effect = pkg_resources.DistributionNotFound - - self.assertRaisesRegex( - rpkgError, r'bodhi-client < 2\.0 is not supported\.', - check_bodhi_version) + @patch('fedpkg.cli.distribution') + def test_no_6_x_version_installed(self, mock_distribution): + mock_distribution.return_value.version = '5.7.5' + self.assertRaisesRegex( + rpkgError, r'bodhi-client < 6\.0\.0 is not supported\.', + check_bodhi_version) @unittest.skipUnless(bodhi, 'Skip if no supported bodhi-client is available')