mercurial/policy.py
changeset 29266 b3a677c82a35
child 29490 b4d117cee636
equal deleted inserted replaced
29265:3f9e68864ccc 29266:b3a677c82a35
       
     1 # policy.py - module policy logic for Mercurial.
       
     2 #
       
     3 # Copyright 2015 Gregory Szorc <gregory.szorc@gmail.com>
       
     4 #
       
     5 # This software may be used and distributed according to the terms of the
       
     6 # GNU General Public License version 2 or any later version.
       
     7 
       
     8 from __future__ import absolute_import
       
     9 
       
    10 import os
       
    11 import sys
       
    12 
       
    13 # Rules for how modules can be loaded. Values are:
       
    14 #
       
    15 #    c - require C extensions
       
    16 #    allow - allow pure Python implementation when C loading fails
       
    17 #    py - only load pure Python modules
       
    18 #
       
    19 # By default, require the C extensions for performance reasons.
       
    20 policy = 'c'
       
    21 try:
       
    22     from . import __modulepolicy__
       
    23     policy = __modulepolicy__.modulepolicy
       
    24 except ImportError:
       
    25     pass
       
    26 
       
    27 # PyPy doesn't load C extensions.
       
    28 #
       
    29 # The canonical way to do this is to test platform.python_implementation().
       
    30 # But we don't import platform and don't bloat for it here.
       
    31 if '__pypy__' in sys.builtin_module_names:
       
    32     policy = 'py'
       
    33 
       
    34 # Our C extensions aren't yet compatible with Python 3. So use pure Python
       
    35 # on Python 3 for now.
       
    36 if sys.version_info[0] >= 3:
       
    37     policy = 'py'
       
    38 
       
    39 # Environment variable can always force settings.
       
    40 policy = os.environ.get('HGMODULEPOLICY', policy)