[PATCH 2 of 3 rfc] modulepolicy: add the cffi policy

Maciej Fijalkowski fijall at gmail.com
Mon Mar 7 10:43:16 EST 2016


# HG changeset patch
# User fijal
# Date 1456408807 -3600
#      Thu Feb 25 15:00:07 2016 +0100
# Node ID e04ac5d0fefe1418e1906ec209c0a3657ad8b022
# Parent  c41ede700e5cf47d7eb44408fd2aa0a55f21c81d
modulepolicy: add the cffi policy

This patch adds policies that we will have: cffi, pure and C

cffi is optional for CPython and mandatory for pypy. cffi modules
will be imported from the pure version and used if they're importable.

This patch is not intended for merging, just an RFC for further
discussions

diff -r c41ede700e5c -r e04ac5d0fefe mercurial/__init__.py
--- a/mercurial/__init__.py	Mon Feb 22 11:06:27 2016 +0100
+++ b/mercurial/__init__.py	Thu Feb 25 15:00:07 2016 +0100
@@ -17,9 +17,13 @@
 # Rules for how modules can be loaded. Values are:
 #
 #    c - require C extensions
-#    allow - allow pure Python implementation when C loading fails
+#    allow - allow cffi or pure Python implementation when C loading fails
+#    cffi - required cffi versions (implemented within pure module)
+#    cffi-allow - allow pure Python implementation if cffi version is missing
 #    py - only load pure Python modules
 modulepolicy = '@MODULELOADPOLICY@'
+policynoc = ('cffi', 'cffi-allow', 'py')
+policynocffi = ('c', 'py')
 
 # By default, require the C extensions for performance reasons.
 if modulepolicy == '@' 'MODULELOADPOLICY' '@':
@@ -74,7 +78,7 @@
                 return zl
 
             try:
-                if modulepolicy == 'py':
+                if modulepolicy in policynoc:
                     raise ImportError()
 
                 zl = ziploader('mercurial')
@@ -101,7 +105,7 @@
         stem = name.split('.')[-1]
 
         try:
-            if modulepolicy == 'py':
+            if modulepolicy in policynoc:
                 raise ImportError()
 
             modinfo = imp.find_module(stem, mercurial.__path__)


More information about the Mercurial-devel mailing list