comparison mercurial/__init__.py @ 42207:7ed472e79096

py3: handle meta-path finders that only use pre-python3.4 API
author Ludovic Chabant <ludovic@chabant.com>
date Fri, 19 Apr 2019 14:25:18 +0000
parents 4277e20cfec4
children d28d91f9f35a
comparison
equal deleted inserted replaced
42206:bed4c308fc56 42207:7ed472e79096
52 spec = None 52 spec = None
53 for finder in sys.meta_path: 53 for finder in sys.meta_path:
54 if finder == self: 54 if finder == self:
55 continue 55 continue
56 56
57 spec = finder.find_spec(fullname, path, target=target) 57 # Originally the API was a `find_module` method, but it was
58 # renamed to `find_spec` in python 3.4, with a new `target`
59 # argument.
60 find_spec_method = getattr(finder, 'find_spec', None)
61 if find_spec_method:
62 spec = find_spec_method(fullname, path, target=target)
63 else:
64 spec = finder.find_module(fullname)
65 if spec is not None:
66 spec = importlib.util.spec_from_loader(fullname, spec)
58 if spec: 67 if spec:
59 break 68 break
60 69
61 # This is a Mercurial-related module but we couldn't find it 70 # This is a Mercurial-related module but we couldn't find it
62 # using the previously-registered finders. This likely means 71 # using the previously-registered finders. This likely means