Mercurial > hg
diff mercurial/policy.py @ 33760:cd2aca0808f8
policy: reroute proxy modules internally
This allows us to split encoding functions from pure.parsers without doing
that for cext.parsers. See the next patch for why.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Mon, 31 Jul 2017 23:40:36 +0900 |
parents | 3f5d675fddf4 |
children | f5fc54e7e467 |
line wrap: on
line diff
--- a/mercurial/policy.py Mon Jul 31 22:58:06 2017 +0900 +++ b/mercurial/policy.py Mon Jul 31 23:40:36 2017 +0900 @@ -78,6 +78,13 @@ (r'cext', r'parsers'): 1, } +# map import request to other package or module +_modredirects = { + (r'cffi', r'base85'): (r'pure', r'base85'), + (r'cffi', r'diffhelpers'): (r'pure', r'diffhelpers'), + (r'cffi', r'parsers'): (r'pure', r'parsers'), +} + def _checkmod(pkgname, modname, mod): expected = _cextversions.get((pkgname, modname)) actual = getattr(mod, r'version', None) @@ -94,11 +101,14 @@ raise ImportError(r'invalid HGMODULEPOLICY %r' % policy) assert verpkg or purepkg if verpkg: + pn, mn = _modredirects.get((verpkg, modname), (verpkg, modname)) try: - mod = _importfrom(verpkg, modname) - _checkmod(verpkg, modname, mod) + mod = _importfrom(pn, mn) + if pn == verpkg: + _checkmod(pn, mn, mod) return mod except ImportError: if not purepkg: raise - return _importfrom(purepkg, modname) + pn, mn = _modredirects.get((purepkg, modname), (purepkg, modname)) + return _importfrom(pn, mn)