Mercurial > hg
comparison mercurial/__init__.py @ 43105:649d3ac37a12
py3: define and use pycompat.iteritems() for hgext/
.iteritems() -> .items() is the last source transform being performed.
But it is also the most widely used.
This commit adds a pycompat.iteritems symbol and imports it in place
of .iteritems() for usage in hgext/. I chose to stop at just hgext/
because the patch will be large and it is an easy boundary to stop at
since we can disable source transformation on a per-package basis.
There are places where the type does implement items() and we could
call items() directly. However, this would require critical thought
and I thought it would be easier to just blindly change the code. We
know which call sites need to be audited in the future because they
have "pycompat.iteritems."
With this change, we no longer perform source transformation on
hgext!
Differential Revision: https://phab.mercurial-scm.org/D7014
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sun, 06 Oct 2019 19:25:18 -0400 |
parents | 74802979dd9d |
children | d783f945a701 |
comparison
equal
deleted
inserted
replaced
43104:74802979dd9d | 43105:649d3ac37a12 |
---|---|
29 class hgpathentryfinder(importlib.abc.MetaPathFinder): | 29 class hgpathentryfinder(importlib.abc.MetaPathFinder): |
30 """A sys.meta_path finder that uses a custom module loader.""" | 30 """A sys.meta_path finder that uses a custom module loader.""" |
31 | 31 |
32 def find_spec(self, fullname, path, target=None): | 32 def find_spec(self, fullname, path, target=None): |
33 # Only handle Mercurial-related modules. | 33 # Only handle Mercurial-related modules. |
34 if not fullname.startswith(('mercurial.', 'hgext.')): | 34 if not fullname.startswith('mercurial.'): |
35 return None | 35 return None |
36 # don't try to parse binary | 36 # don't try to parse binary |
37 if fullname.startswith('mercurial.cext.'): | 37 if fullname.startswith('mercurial.cext.'): |
38 return None | 38 return None |
39 # third-party packages are expected to be dual-version clean | 39 # third-party packages are expected to be dual-version clean |
43 if fullname.startswith('mercurial.zstd'): | 43 if fullname.startswith('mercurial.zstd'): |
44 return None | 44 return None |
45 # rustext is built for the right python version, | 45 # rustext is built for the right python version, |
46 # don't try and mangle it | 46 # don't try and mangle it |
47 if fullname.startswith('mercurial.rustext'): | 47 if fullname.startswith('mercurial.rustext'): |
48 return None | |
49 # pywatchman is already dual-version clean, don't try and mangle it | |
50 if fullname.startswith('hgext.fsmonitor.pywatchman'): | |
51 return None | 48 return None |
52 | 49 |
53 # Try to find the module using other registered finders. | 50 # Try to find the module using other registered finders. |
54 spec = None | 51 spec = None |
55 for finder in sys.meta_path: | 52 for finder in sys.meta_path: |
129 | 126 |
130 # Header to add to bytecode files. This MUST be changed when | 127 # Header to add to bytecode files. This MUST be changed when |
131 # ``replacetoken`` or any mechanism that changes semantics of module | 128 # ``replacetoken`` or any mechanism that changes semantics of module |
132 # loading is changed. Otherwise cached bytecode may get loaded without | 129 # loading is changed. Otherwise cached bytecode may get loaded without |
133 # the new transformation mechanisms applied. | 130 # the new transformation mechanisms applied. |
134 BYTECODEHEADER = b'HG\x00\x15' | 131 BYTECODEHEADER = b'HG\x00\x16' |
135 | 132 |
136 class hgloader(importlib.machinery.SourceFileLoader): | 133 class hgloader(importlib.machinery.SourceFileLoader): |
137 """Custom module loader that transforms source code. | 134 """Custom module loader that transforms source code. |
138 | 135 |
139 When the source code is converted to a code object, we transform | 136 When the source code is converted to a code object, we transform |