Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/extensions.py @ 43106:d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
This commit finishes porting .iteritems() to pycompat.iteritems()
for the mercurial package.
The translation of .iteritems() to .items() was the last conversion
performed by the source transformer. With the porting to pycompat
complete, we no longer have a need for the source transformer. So
the source transformer has been removed. Good riddance! The code
base is now compatible with Python 2 and Python 3.
For the record, as the person who introduced the source transformer,
it brings me joy to delete it. It accomplished its goal to facilitate
a port to Python 3 without overly burdening people on some painful
low-level differences between Python 2 and 3. It is unfortunate we
still have to wallpaper over many differences with the pycompat
shim. But it is what it is.
Differential Revision: https://phab.mercurial-scm.org/D7015
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 07 Oct 2019 00:04:04 -0400 |
parents | c59eb1560c44 |
children | 101ae8bbfa02 |
comparison
equal
deleted
inserted
replaced
43105:649d3ac37a12 | 43106:d783f945a701 |
---|---|
72 '''return module with given extension name''' | 72 '''return module with given extension name''' |
73 mod = None | 73 mod = None |
74 try: | 74 try: |
75 mod = _extensions[name] | 75 mod = _extensions[name] |
76 except KeyError: | 76 except KeyError: |
77 for k, v in _extensions.iteritems(): | 77 for k, v in pycompat.iteritems(_extensions): |
78 if k.endswith(b'.' + name) or k.endswith(b'/' + name): | 78 if k.endswith(b'.' + name) or k.endswith(b'/' + name): |
79 mod = v | 79 mod = v |
80 break | 80 break |
81 if not mod: | 81 if not mod: |
82 raise KeyError(name) | 82 raise KeyError(name) |
165 _cmdfuncattrs = (b'norepo', b'optionalrepo', b'inferrepo') | 165 _cmdfuncattrs = (b'norepo', b'optionalrepo', b'inferrepo') |
166 | 166 |
167 | 167 |
168 def _validatecmdtable(ui, cmdtable): | 168 def _validatecmdtable(ui, cmdtable): |
169 """Check if extension commands have required attributes""" | 169 """Check if extension commands have required attributes""" |
170 for c, e in cmdtable.iteritems(): | 170 for c, e in pycompat.iteritems(cmdtable): |
171 f = e[0] | 171 f = e[0] |
172 missing = [a for a in _cmdfuncattrs if not util.safehasattr(f, a)] | 172 missing = [a for a in _cmdfuncattrs if not util.safehasattr(f, a)] |
173 if not missing: | 173 if not missing: |
174 continue | 174 continue |
175 raise error.ProgrammingError( | 175 raise error.ProgrammingError( |
549 extensions.wrapcommand(commands.table, 'bookmarks', exbookmarks, | 549 extensions.wrapcommand(commands.table, 'bookmarks', exbookmarks, |
550 synopsis, docstring) | 550 synopsis, docstring) |
551 ''' | 551 ''' |
552 assert callable(wrapper) | 552 assert callable(wrapper) |
553 aliases, entry = cmdutil.findcmd(command, table) | 553 aliases, entry = cmdutil.findcmd(command, table) |
554 for alias, e in table.iteritems(): | 554 for alias, e in pycompat.iteritems(table): |
555 if e is entry: | 555 if e is entry: |
556 key = alias | 556 key = alias |
557 break | 557 break |
558 | 558 |
559 origfn = entry[0] | 559 origfn = entry[0] |
723 if not os.path.exists(path): | 723 if not os.path.exists(path): |
724 continue | 724 continue |
725 if name in exts or name in _order or name == b'__init__': | 725 if name in exts or name in _order or name == b'__init__': |
726 continue | 726 continue |
727 exts[name] = path | 727 exts[name] = path |
728 for name, path in _disabledextensions.iteritems(): | 728 for name, path in pycompat.iteritems(_disabledextensions): |
729 # If no path was provided for a disabled extension (e.g. "color=!"), | 729 # If no path was provided for a disabled extension (e.g. "color=!"), |
730 # don't replace the path we already found by the scan above. | 730 # don't replace the path we already found by the scan above. |
731 if path: | 731 if path: |
732 exts[name] = path | 732 exts[name] = path |
733 return exts | 733 return exts |
785 try: | 785 try: |
786 from hgext import __index__ | 786 from hgext import __index__ |
787 | 787 |
788 return dict( | 788 return dict( |
789 (name, gettext(desc)) | 789 (name, gettext(desc)) |
790 for name, desc in __index__.docs.iteritems() | 790 for name, desc in pycompat.iteritems(__index__.docs) |
791 if name not in _order | 791 if name not in _order |
792 ) | 792 ) |
793 except (ImportError, AttributeError): | 793 except (ImportError, AttributeError): |
794 pass | 794 pass |
795 | 795 |
796 paths = _disabledpaths() | 796 paths = _disabledpaths() |
797 if not paths: | 797 if not paths: |
798 return {} | 798 return {} |
799 | 799 |
800 exts = {} | 800 exts = {} |
801 for name, path in paths.iteritems(): | 801 for name, path in pycompat.iteritems(paths): |
802 doc = _disabledhelp(path) | 802 doc = _disabledhelp(path) |
803 if doc: | 803 if doc: |
804 exts[name] = doc.splitlines()[0] | 804 exts[name] = doc.splitlines()[0] |
805 | 805 |
806 return exts | 806 return exts |
895 path = paths.pop(cmd, None) | 895 path = paths.pop(cmd, None) |
896 if path: | 896 if path: |
897 ext = _finddisabledcmd(ui, cmd, cmd, path, strict=strict) | 897 ext = _finddisabledcmd(ui, cmd, cmd, path, strict=strict) |
898 if not ext: | 898 if not ext: |
899 # otherwise, interrogate each extension until there's a match | 899 # otherwise, interrogate each extension until there's a match |
900 for name, path in paths.iteritems(): | 900 for name, path in pycompat.iteritems(paths): |
901 ext = _finddisabledcmd(ui, cmd, name, path, strict=strict) | 901 ext = _finddisabledcmd(ui, cmd, name, path, strict=strict) |
902 if ext: | 902 if ext: |
903 break | 903 break |
904 if ext: | 904 if ext: |
905 return ext | 905 return ext |
919 return exts | 919 return exts |
920 | 920 |
921 | 921 |
922 def notloaded(): | 922 def notloaded(): |
923 '''return short names of extensions that failed to load''' | 923 '''return short names of extensions that failed to load''' |
924 return [name for name, mod in _extensions.iteritems() if mod is None] | 924 return [ |
925 name for name, mod in pycompat.iteritems(_extensions) if mod is None | |
926 ] | |
925 | 927 |
926 | 928 |
927 def moduleversion(module): | 929 def moduleversion(module): |
928 '''return version information from given module as a string''' | 930 '''return version information from given module as a string''' |
929 if util.safehasattr(module, b'getversion') and callable(module.getversion): | 931 if util.safehasattr(module, b'getversion') and callable(module.getversion): |