Patchwork [07,of,10] policy: extend API version checks for cffi

login
register
mail settings
Submitter Yuya Nishihara
Date May 28, 2017, 1:05 p.m.
Message ID <a8b227de35d637507a81.1495976712@mimosa>
Download mbox | patch
Permalink /patch/20980/
State Accepted
Headers show

Comments

Yuya Nishihara - May 28, 2017, 1:05 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1495953952 -32400
#      Sun May 28 15:45:52 2017 +0900
# Node ID a8b227de35d637507a81d28e421de846e00a2403
# Parent  0120b66d89008c4baece3eb03cee66a55b572452
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.

Patch

diff --git a/mercurial/policy.py b/mercurial/policy.py
--- a/mercurial/policy.py
+++ b/mercurial/policy.py
@@ -72,16 +72,16 @@  def _importfrom(pkgname, modname):
 
 # keep in sync with "version" in C modules
 _cextversions = {
-    r'base85': 1,
-    r'bdiff': 1,
-    r'diffhelpers': 1,
-    r'mpatch': 1,
-    r'osutil': 1,
-    r'parsers': 1,
+    (r'cext', r'base85'): 1,
+    (r'cext', r'bdiff'): 1,
+    (r'cext', r'diffhelpers'): 1,
+    (r'cext', r'mpatch'): 1,
+    (r'cext', r'osutil'): 1,
+    (r'cext', r'parsers'): 1,
 }
 
 def _checkmod(pkgname, modname, mod):
-    expected = _cextversions.get(modname)
+    expected = _cextversions.get((pkgname, modname))
     actual = getattr(mod, r'version', None)
     if actual != expected:
         raise ImportError(r'cannot import module %s.%s '