Mercurial > hg
comparison mercurial/policy.py @ 32511:2e431fb98c6b
policy: extend API version checks for cffi
This is just a stub for future extension. I could add a version constant to
CFFI modules by putting it to both ffi.set_source() and ffi.cdef(), but that
doesn't seem right. So for now, cffi modules will be explicitly unversioned
(i.e. version constant must be undefined or set to None.) We can revisit it
later when we need to consider CFFI support more seriously.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 28 May 2017 15:45:52 +0900 |
parents | 28b773aa3ff2 |
children | 0e8b0b9a7acc |
comparison
equal
deleted
inserted
replaced
32510:50eaccb8353f | 32511:2e431fb98c6b |
---|---|
70 getattr(mod, r'__doc__', None) | 70 getattr(mod, r'__doc__', None) |
71 return fakelocals[modname] | 71 return fakelocals[modname] |
72 | 72 |
73 # keep in sync with "version" in C modules | 73 # keep in sync with "version" in C modules |
74 _cextversions = { | 74 _cextversions = { |
75 r'base85': 1, | 75 (r'cext', r'base85'): 1, |
76 r'bdiff': 1, | 76 (r'cext', r'bdiff'): 1, |
77 r'diffhelpers': 1, | 77 (r'cext', r'diffhelpers'): 1, |
78 r'mpatch': 1, | 78 (r'cext', r'mpatch'): 1, |
79 r'osutil': 1, | 79 (r'cext', r'osutil'): 1, |
80 r'parsers': 1, | 80 (r'cext', r'parsers'): 1, |
81 } | 81 } |
82 | 82 |
83 def _checkmod(pkgname, modname, mod): | 83 def _checkmod(pkgname, modname, mod): |
84 expected = _cextversions.get(modname) | 84 expected = _cextversions.get((pkgname, modname)) |
85 actual = getattr(mod, r'version', None) | 85 actual = getattr(mod, r'version', None) |
86 if actual != expected: | 86 if actual != expected: |
87 raise ImportError(r'cannot import module %s.%s ' | 87 raise ImportError(r'cannot import module %s.%s ' |
88 r'(expected version: %d, actual: %r)' | 88 r'(expected version: %d, actual: %r)' |
89 % (pkgname, modname, expected, actual)) | 89 % (pkgname, modname, expected, actual)) |