# HG changeset patch # User timeless # Date 2016-03-09 19:55:45 # Node ID b3a677c82a35e499e84f69245f65e682c4be698f # Parent 3f9e68864ccc1575ae3f2df14b78df6779daa1f7 debuginstall: expose modulepolicy With this, you can check for pure easily: $ HGMODULEPOLICY=py ./hg debuginstall -T "{hgmodulepolicy}" py diff --git a/mercurial/__init__.py b/mercurial/__init__.py --- a/mercurial/__init__.py +++ b/mercurial/__init__.py @@ -12,36 +12,13 @@ import os import sys import zipimport +from . import ( + policy +) + __all__ = [] -# Rules for how modules can be loaded. Values are: -# -# c - require C extensions -# allow - allow pure Python implementation when C loading fails -# py - only load pure Python modules -# -# By default, require the C extensions for performance reasons. -modulepolicy = 'c' -try: - from . import __modulepolicy__ - modulepolicy = __modulepolicy__.modulepolicy -except ImportError: - pass - -# 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' - -# Our C extensions aren't yet compatible with Python 3. So use pure Python -# on Python 3 for now. -if sys.version_info[0] >= 3: - modulepolicy = 'py' - -# Environment variable can always force settings. -modulepolicy = os.environ.get('HGMODULEPOLICY', modulepolicy) +modulepolicy = policy.policy # Modules that have both Python and C implementations. See also the # set of .py files under mercurial/pure/. diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -59,6 +59,7 @@ from . import ( obsolete, patch, phases, + policy, pvec, repair, revlog, @@ -2749,6 +2750,8 @@ def debuginstall(ui, **opts): '+'.join(hgver.split('+')[1:])) # compiled modules + fm.write('hgmodulepolicy', _("checking module policy (%s)\n"), + policy.policy) fm.write('hgmodules', _("checking installed modules (%s)...\n"), os.path.dirname(__file__)) diff --git a/mercurial/policy.py b/mercurial/policy.py new file mode 100644 --- /dev/null +++ b/mercurial/policy.py @@ -0,0 +1,40 @@ +# policy.py - module policy logic for Mercurial. +# +# Copyright 2015 Gregory Szorc +# +# This software may be used and distributed according to the terms of the +# GNU General Public License version 2 or any later version. + +from __future__ import absolute_import + +import os +import sys + +# Rules for how modules can be loaded. Values are: +# +# c - require C extensions +# allow - allow pure Python implementation when C loading fails +# py - only load pure Python modules +# +# By default, require the C extensions for performance reasons. +policy = 'c' +try: + from . import __modulepolicy__ + policy = __modulepolicy__.modulepolicy +except ImportError: + pass + +# 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: + policy = 'py' + +# Our C extensions aren't yet compatible with Python 3. So use pure Python +# on Python 3 for now. +if sys.version_info[0] >= 3: + policy = 'py' + +# Environment variable can always force settings. +policy = os.environ.get('HGMODULEPOLICY', policy) diff --git a/tests/test-install.t b/tests/test-install.t --- a/tests/test-install.t +++ b/tests/test-install.t @@ -6,6 +6,7 @@ hg debuginstall checking Python lib (*lib*)... (glob) checking Mercurial version (*) (glob) checking Mercurial custom build (*) (glob) + checking module policy (*) (glob) checking installed modules (*mercurial)... (glob) checking templates (*mercurial?templates)... (glob) checking default template (*mercurial?templates?map-cmdline.default) (glob) @@ -25,6 +26,7 @@ hg debuginstall JSON "encoding": "ascii", "encodingerror": null, "extensionserror": null, + "hgmodulepolicy": "*", (glob) "hgmodules": "*mercurial", (glob) "hgver": "*", (glob) "hgverextra": "*", (glob) @@ -47,6 +49,7 @@ hg debuginstall with no username checking Python lib (*lib*)... (glob) checking Mercurial version (*) (glob) checking Mercurial custom build (*) (glob) + checking module policy (*) (glob) checking installed modules (*mercurial)... (glob) checking templates (*mercurial?templates)... (glob) checking default template (*mercurial?templates?map-cmdline.default) (glob) @@ -70,6 +73,7 @@ path variables are expanded (~ is the sa checking Python lib (*lib*)... (glob) checking Mercurial version (*) (glob) checking Mercurial custom build (*) (glob) + checking module policy (*) (glob) checking installed modules (*mercurial)... (glob) checking templates (*mercurial?templates)... (glob) checking default template (*mercurial?templates?map-cmdline.default) (glob)