summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Finucane <stephenfin@redhat.com>2022-09-09 16:50:45 +0100
committerStephen Finucane <stephenfin@redhat.com>2022-10-04 11:23:17 +0100
commit663d56c9535c64f4f8bd363abf69406975585ee9 (patch)
tree6d1e83437486759d34f591dc11ff5a5cdc58dea2
parent55e9e1e5e880924b62867f152faa72e300cca451 (diff)
downloadstevedore-663d56c9535c64f4f8bd363abf69406975585ee9.tar.gz
Fix compatibility with Python 3.10, 3.9.11
A fix to 'importlib.metadata' in Python 3.10 [1], later backported to 3.9 and released in 3.9.11 [2], has broken our tests. Fix them. [1] https://github.com/python/cpython/commit/b1e286860742e7ba6fadc75e3ddb6c2899a56919 [2] https://github.com/python/cpython/commit/177be52517da9a876a3f9e670f88c4731b906986 Signed-off-by: Stephen Finucane <stephenfin@redhat.com> Closes-bug: #1966040 Change-Id: Iff536d4f4267efbebc4be1e7e5da8a9fde39f79b
-rw-r--r--stevedore/extension.py30
1 files changed, 19 insertions, 11 deletions
diff --git a/stevedore/extension.py b/stevedore/extension.py
index 06ac067..d9ee084 100644
--- a/stevedore/extension.py
+++ b/stevedore/extension.py
@@ -61,17 +61,25 @@ class Extension(object):
@property
def extras(self):
"""The 'extras' settings for the plugin."""
- # NOTE: The underlying package returns re.Match objects for
- # some reason. Translate those to the matched strings, which
- # seem more useful.
- return [
- # Python 3.6 returns _sre.SRE_Match objects. Later
- # versions of python return re.Match objects. Both types
- # have a 'string' attribute containing the text that
- # matched the pattern.
- getattr(e, 'string', e)
- for e in self.entry_point.extras
- ]
+ # NOTE: The underlying package returned re.Match objects until this was
+ # fixed in importlib-metadata 4.11.3. This was fixed in Python 3.10 and
+ # backported to Python 3.9.11. For older versions without this fix,
+ # translate the re.Match objects to the matched strings, which seem
+ # more useful.
+ extras = []
+ for extra in self.entry_point.extras:
+ if isinstance(extra, str):
+ # We were previously returning the whole string including
+ # backets. We need to continue doing so to preserve API
+ # compatibility.
+ extras.append(f'[{extra}]')
+ else:
+ # Python 3.6 returns _sre.SRE_Match objects. Later
+ # versions of python return re.Match objects. Both types
+ # have a 'string' attribute containing the text that
+ # matched the pattern.
+ extras.append(getattr(extra, 'string', extra))
+ return extras
@property
def attr(self):