Mercurial > hg
comparison mercurial/__init__.py @ 32425:397e3a2e9347
python3: allow hgloader to work with lazy loaders
Don't clobber the loader returned from find_spec.
This brings `hg version` down from 0.27 seconds to 0.17.
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Sun, 21 May 2017 13:26:17 -0700 |
parents | 0906b85bf222 |
children | 942051a29fb6 |
comparison
equal
deleted
inserted
replaced
32424:b4810bf95c03 | 32425:397e3a2e9347 |
---|---|
51 if not spec: | 51 if not spec: |
52 return None | 52 return None |
53 | 53 |
54 # TODO need to support loaders from alternate specs, like zip | 54 # TODO need to support loaders from alternate specs, like zip |
55 # loaders. | 55 # loaders. |
56 spec.loader = hgloader(spec.name, spec.origin) | 56 loader = hgloader(spec.name, spec.origin) |
57 # Can't use util.safehasattr here because that would require | |
58 # importing util, and we're in import code. | |
59 if hasattr(spec.loader, 'loader'): # hasattr-py3-only | |
60 # This is a nested loader (maybe a lazy loader?) | |
61 spec.loader.loader = loader | |
62 else: | |
63 spec.loader = loader | |
57 return spec | 64 return spec |
58 | 65 |
59 def replacetokens(tokens, fullname): | 66 def replacetokens(tokens, fullname): |
60 """Transform a stream of tokens from raw to Python 3. | 67 """Transform a stream of tokens from raw to Python 3. |
61 | 68 |