py3: handle meta-path finders that only use pre-python3.4 API
authorLudovic Chabant <ludovic@chabant.com>
Fri, 19 Apr 2019 14:25:18 +0000
changeset 42207 7ed472e79096
parent 42206 bed4c308fc56
child 42208 91104f10ff65
py3: handle meta-path finders that only use pre-python3.4 API
mercurial/__init__.py
--- a/mercurial/__init__.py	Fri Apr 26 17:41:22 2019 -0700
+++ b/mercurial/__init__.py	Fri Apr 19 14:25:18 2019 +0000
@@ -54,7 +54,16 @@
                 if finder == self:
                     continue
 
-                spec = finder.find_spec(fullname, path, target=target)
+                # Originally the API was a `find_module` method, but it was
+                # renamed to `find_spec` in python 3.4, with a new `target`
+                # argument.
+                find_spec_method = getattr(finder, 'find_spec', None)
+                if find_spec_method:
+                    spec = find_spec_method(fullname, path, target=target)
+                else:
+                    spec = finder.find_module(fullname)
+                    if spec is not None:
+                        spec = importlib.util.spec_from_loader(fullname, spec)
                 if spec:
                     break