Patchwork [5,of,6,import-refactor,V3] mercurial: don't load C extensions from PyPy

login
register
mail settings
Submitter Gregory Szorc
Date Dec. 4, 2015, 5:51 a.m.
Message ID <dd8b23489d2a5f558090.1449208271@ubuntu-main>
Download mbox | patch
Permalink /patch/11803/
State Accepted
Delegated to: Yuya Nishihara
Headers show

Comments

Gregory Szorc - Dec. 4, 2015, 5:51 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1448432511 28800
#      Tue Nov 24 22:21:51 2015 -0800
# Node ID dd8b23489d2a5f5580905c995333d139fe457d1c
# Parent  1caabea1ce8e535aee622f3678a92188c461b648
mercurial: don't load C extensions from PyPy

PyPy isn't compatible with Python C extensions.

With this patch, the module load policy is automatically to "Python
only" when run under PyPy. `hg` and other Python scripts importing
mercurial.* modules will run from the source checkout or any
installation when executed with PyPy. This should enable people to
more easily experiment with PyPy and its potentially significant
performance benefits over CPython!

Patch

diff --git a/mercurial/__init__.py b/mercurial/__init__.py
--- a/mercurial/__init__.py
+++ b/mercurial/__init__.py
@@ -19,16 +19,23 @@  import sys
 #    allow - allow pure Python implementation when C loading fails
 #    py - only load pure Python modules
 modulepolicy = '@MODULELOADPOLICY@'
 
 # By default, require the C extensions for performance reasons.
 if modulepolicy == '@' 'MODULELOADPOLICY' '@':
     modulepolicy = 'c'
 
+# PyPy doesn't load C extensions.
+#
+# The canonical way to do this is to test platform.python_implementation().
+# But we don't import platform and don't bloat for it here.
+if '__pypy__' in sys.builtin_module_names:
+    modulepolicy = 'py'
+
 # Environment variable can always force settings.
 modulepolicy = os.environ.get('HGMODULEPOLICY', modulepolicy)
 
 # Modules that have both Python and C implementations. See also the
 # set of .py files under mercurial/pure/.
 _dualmodules = set([
     'mercurial.base85',
     'mercurial.bdiff',