| |
@@ -21,13 +21,18 @@
|
| |
from tempfile import mkdtemp, mkstemp
|
| |
|
| |
import git
|
| |
- import pkg_resources
|
| |
+ # 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
|
| |
+
|
| |
import six
|
| |
from six.moves import StringIO
|
| |
from six.moves.configparser import NoOptionError, NoSectionError
|
| |
|
| |
import fedpkg.cli
|
| |
- from fedpkg import parse_version, bodhi_version
|
| |
+ from fedpkg import bodhi_version
|
| |
from fedpkg.bugzilla import BugzillaClient
|
| |
from fedpkg.cli import check_bodhi_version
|
| |
from freezegun import freeze_time
|
| |
@@ -1609,16 +1614,34 @@
|
| |
self.assertEqual(str(error), expected_error)
|
| |
|
| |
|
| |
- class TestCheckBodhiVersion(unittest.TestCase):
|
| |
- """Test check_bodhi_version"""
|
| |
+ # Use deprecated pkg_resources if importlib isn't available (python 3.6)
|
| |
+ try:
|
| |
+ import importlib.metadata
|
| |
|
| |
- @patch('pkg_resources.get_distribution')
|
| |
- def test_no_2_x_version_installed(self, get_distribution):
|
| |
- get_distribution.side_effect = pkg_resources.DistributionNotFound
|
| |
+ class TestCheckBodhiVersion(unittest.TestCase):
|
| |
+ """Test check_bodhi_version"""
|
| |
|
| |
- six.assertRaisesRegex(
|
| |
- self, rpkgError, r'bodhi-client < 2\.0 is not supported\.',
|
| |
- check_bodhi_version)
|
| |
+ @patch('importlib.metadata.distribution')
|
| |
+ def test_no_2_x_version_installed(self, distribution):
|
| |
+ distribution.side_effect = importlib.metadata.PackageNotFoundError
|
| |
+
|
| |
+ six.assertRaisesRegex(
|
| |
+ self, rpkgError, r'bodhi-client < 2\.0 is not supported\.',
|
| |
+ 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
|
| |
+
|
| |
+ six.assertRaisesRegex(
|
| |
+ self, rpkgError, r'bodhi-client < 2\.0 is not supported\.',
|
| |
+ check_bodhi_version)
|
| |
|
| |
|
| |
@unittest.skipUnless(bodhi, 'Skip if no supported bodhi-client is available')
|
| |
I've been studying fedpkg code and noticed that the tests were failing to run on python 3.12. The main cause of this is that the pkg_resources library can't be found during the testing process when testing on python 3.12.
Digging around, I found out that the thing that causes this problem is that python 3.12 stopped preinstalling the
setuptools
library in virtual environments created with venv [0]. This can be easily fixed by adding thesetuptools
requirement to therequirements.txt
file, but I also noticed that the pkg_resources API being used in fedpkg was a deprecated API [1], so I changed the code so that fedpkg prioritizes using the importlib library when available instead as recommended by upstream[1].[0] https://docs.python.org/3/whatsnew/3.12.html
[1] https://setuptools.pypa.io/en/latest/pkg_resources.html