Merge "Fix compatibility with Python 3.12, importlib-metadata 5.0"

This commit is contained in:
Zuul 2022-10-05 11:56:41 +00:00 committed by Gerrit Code Review
commit 135e285ec6
2 changed files with 18 additions and 2 deletions

View File

@ -97,8 +97,16 @@ def _hash_settings_for_path(path):
return (h.hexdigest(), paths)
def _build_cacheable_data(path):
def _build_cacheable_data():
real_groups = importlib_metadata.entry_points()
if not isinstance(real_groups, dict):
# importlib-metadata 4.0 or later (or stdlib importlib.metadata in
# Python 3.9 or later)
real_groups = {
name: real_groups.select(name=name) for name in real_groups.names
}
# Convert the namedtuple values to regular tuples
groups = {}
for name, group_data in real_groups.items():
@ -153,7 +161,7 @@ class Cache:
with open(filename, 'r') as f:
data = json.load(f)
except (IOError, json.JSONDecodeError):
data = _build_cacheable_data(path)
data = _build_cacheable_data()
data['path_values'] = path_values
if not self._disable_caching:
try:

View File

@ -54,3 +54,11 @@ class TestCache(utils.TestCase):
mock_open.side_effect = IOError
sot._get_data_for_path('fake')
mock_mkdir.assert_not_called()
def test__build_cacheable_data(self):
# this is a rubbish test as we don't actually do anything with the
# data, but it's too hard to script since it's totally environmentally
# dependent and mocking out the underlying calls would remove the value
# of this test (we want to test those underlying API calls)
ret = _cache._build_cacheable_data()
self.assertIsInstance(ret['groups'], dict)