Show More
@@ -1,49 +1,49 | |||
|
1 | 1 | # policy.py - module policy logic for Mercurial. |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2015 Gregory Szorc <gregory.szorc@gmail.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2 or any later version. |
|
7 | 7 | |
|
8 | 8 | from __future__ import absolute_import |
|
9 | 9 | |
|
10 | 10 | import os |
|
11 | 11 | import sys |
|
12 | 12 | |
|
13 | 13 | # Rules for how modules can be loaded. Values are: |
|
14 | 14 | # |
|
15 | 15 | # c - require C extensions |
|
16 | 16 | # allow - allow pure Python implementation when C loading fails |
|
17 | 17 | # cffi - required cffi versions (implemented within pure module) |
|
18 | 18 | # cffi-allow - allow pure Python implementation if cffi version is missing |
|
19 | 19 | # py - only load pure Python modules |
|
20 | 20 | # |
|
21 | 21 | # By default, require the C extensions for performance reasons. |
|
22 | 22 | policy = b'c' |
|
23 | 23 | policynoc = (b'cffi', b'cffi-allow', b'py') |
|
24 | 24 | policynocffi = (b'c', b'py') |
|
25 | 25 | |
|
26 | 26 | try: |
|
27 | 27 | from . import __modulepolicy__ |
|
28 | 28 | policy = __modulepolicy__.modulepolicy |
|
29 | 29 | except ImportError: |
|
30 | 30 | pass |
|
31 | 31 | |
|
32 | 32 | # PyPy doesn't load C extensions. |
|
33 | 33 | # |
|
34 | 34 | # The canonical way to do this is to test platform.python_implementation(). |
|
35 | 35 | # But we don't import platform and don't bloat for it here. |
|
36 | if '__pypy__' in sys.builtin_module_names: | |
|
37 | policy = 'cffi' | |
|
36 | if r'__pypy__' in sys.builtin_module_names: | |
|
37 | policy = b'cffi' | |
|
38 | 38 | |
|
39 | 39 | # Our C extensions aren't yet compatible with Python 3. So use pure Python |
|
40 | 40 | # on Python 3 for now. |
|
41 | 41 | if sys.version_info[0] >= 3: |
|
42 | 42 | policy = b'py' |
|
43 | 43 | |
|
44 | 44 | # Environment variable can always force settings. |
|
45 | 45 | if sys.version_info[0] >= 3: |
|
46 | if 'HGMODULEPOLICY' in os.environ: | |
|
47 | policy = os.environ['HGMODULEPOLICY'].encode('utf-8') | |
|
46 | if r'HGMODULEPOLICY' in os.environ: | |
|
47 | policy = os.environ[r'HGMODULEPOLICY'].encode(r'utf-8') | |
|
48 | 48 | else: |
|
49 | policy = os.environ.get('HGMODULEPOLICY', policy) | |
|
49 | policy = os.environ.get(r'HGMODULEPOLICY', policy) |
General Comments 0
You need to be logged in to leave comments.
Login now