Mercurial > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
33759:a22339d389d4 | 33760:cd2aca0808f8 |
---|---|
76 (r'cext', r'mpatch'): 1, | 76 (r'cext', r'mpatch'): 1, |
77 (r'cext', r'osutil'): 1, | 77 (r'cext', r'osutil'): 1, |
78 (r'cext', r'parsers'): 1, | 78 (r'cext', r'parsers'): 1, |
79 } | 79 } |
80 | 80 |
81 # map import request to other package or module | |
82 _modredirects = { | |
83 (r'cffi', r'base85'): (r'pure', r'base85'), | |
84 (r'cffi', r'diffhelpers'): (r'pure', r'diffhelpers'), | |
85 (r'cffi', r'parsers'): (r'pure', r'parsers'), | |
86 } | |
87 | |
81 def _checkmod(pkgname, modname, mod): | 88 def _checkmod(pkgname, modname, mod): |
82 expected = _cextversions.get((pkgname, modname)) | 89 expected = _cextversions.get((pkgname, modname)) |
83 actual = getattr(mod, r'version', None) | 90 actual = getattr(mod, r'version', None) |
84 if actual != expected: | 91 if actual != expected: |
85 raise ImportError(r'cannot import module %s.%s ' | 92 raise ImportError(r'cannot import module %s.%s ' |
92 verpkg, purepkg = _packageprefs[policy] | 99 verpkg, purepkg = _packageprefs[policy] |
93 except KeyError: | 100 except KeyError: |
94 raise ImportError(r'invalid HGMODULEPOLICY %r' % policy) | 101 raise ImportError(r'invalid HGMODULEPOLICY %r' % policy) |
95 assert verpkg or purepkg | 102 assert verpkg or purepkg |
96 if verpkg: | 103 if verpkg: |
104 pn, mn = _modredirects.get((verpkg, modname), (verpkg, modname)) | |
97 try: | 105 try: |
98 mod = _importfrom(verpkg, modname) | 106 mod = _importfrom(pn, mn) |
99 _checkmod(verpkg, modname, mod) | 107 if pn == verpkg: |
108 _checkmod(pn, mn, mod) | |
100 return mod | 109 return mod |
101 except ImportError: | 110 except ImportError: |
102 if not purepkg: | 111 if not purepkg: |
103 raise | 112 raise |
104 return _importfrom(purepkg, modname) | 113 pn, mn = _modredirects.get((purepkg, modname), (purepkg, modname)) |
114 return _importfrom(pn, mn) |