1 # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 |
1 # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 |
2 # For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt |
2 # For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt |
3 |
3 |
4 """Determine facts about the environment.""" |
4 """Determine facts about the environment.""" |
5 |
5 |
6 import os |
6 import os |
7 import platform |
7 import platform |
8 import sys |
8 import sys |
9 |
9 |
10 # Operating systems. |
10 # Operating systems. |
11 WINDOWS = sys.platform == "win32" |
11 WINDOWS = sys.platform == "win32" |
12 LINUX = sys.platform == "linux2" |
12 LINUX = sys.platform.startswith("linux") |
|
13 |
|
14 # Python versions. We amend version_info with one more value, a zero if an |
|
15 # official version, or 1 if built from source beyond an official version. |
|
16 PYVERSION = sys.version_info + (int(platform.python_version()[-1] == "+"),) |
|
17 PY2 = PYVERSION < (3, 0) |
|
18 PY3 = PYVERSION >= (3, 0) |
13 |
19 |
14 # Python implementations. |
20 # Python implementations. |
15 PYPY = (platform.python_implementation() == 'PyPy') |
21 PYPY = (platform.python_implementation() == 'PyPy') |
16 if PYPY: |
22 if PYPY: |
17 PYPYVERSION = sys.pypy_version_info |
23 PYPYVERSION = sys.pypy_version_info |
18 |
24 |
|
25 PYPY2 = PYPY and PY2 |
|
26 PYPY3 = PYPY and PY3 |
|
27 |
19 JYTHON = (platform.python_implementation() == 'Jython') |
28 JYTHON = (platform.python_implementation() == 'Jython') |
20 IRONPYTHON = (platform.python_implementation() == 'IronPython') |
29 IRONPYTHON = (platform.python_implementation() == 'IronPython') |
21 |
|
22 # Python versions. |
|
23 PYVERSION = sys.version_info |
|
24 PY2 = PYVERSION < (3, 0) |
|
25 PY3 = PYVERSION >= (3, 0) |
|
26 |
30 |
27 # Python behavior |
31 # Python behavior |
28 class PYBEHAVIOR(object): |
32 class PYBEHAVIOR(object): |
29 """Flags indicating this Python's behavior.""" |
33 """Flags indicating this Python's behavior.""" |
30 |
34 |
|
35 # Is "if __debug__" optimized away? |
|
36 optimize_if_debug = (not PYPY) |
|
37 |
|
38 # Is "if not __debug__" optimized away? |
|
39 optimize_if_not_debug = (not PYPY) and (PYVERSION >= (3, 7, 0, 'alpha', 4)) |
|
40 |
31 # Is "if not __debug__" optimized away even better? |
41 # Is "if not __debug__" optimized away even better? |
32 optimize_if_not_debug2 = (not PYPY) and (PYVERSION >= (3, 8, 0, 'beta', 1)) |
42 optimize_if_not_debug2 = (not PYPY) and (PYVERSION >= (3, 8, 0, 'beta', 1)) |
|
43 |
|
44 # Do we have yield-from? |
|
45 yield_from = (PYVERSION >= (3, 3)) |
|
46 |
|
47 # Do we have PEP 420 namespace packages? |
|
48 namespaces_pep420 = (PYVERSION >= (3, 3)) |
|
49 |
|
50 # Do .pyc files have the source file size recorded in them? |
|
51 size_in_pyc = (PYVERSION >= (3, 3)) |
|
52 |
|
53 # Do we have async and await syntax? |
|
54 async_syntax = (PYVERSION >= (3, 5)) |
|
55 |
|
56 # PEP 448 defined additional unpacking generalizations |
|
57 unpackings_pep448 = (PYVERSION >= (3, 5)) |
|
58 |
|
59 # Can co_lnotab have negative deltas? |
|
60 negative_lnotab = (PYVERSION >= (3, 6)) |
|
61 |
|
62 # Do .pyc files conform to PEP 552? Hash-based pyc's. |
|
63 hashed_pyc_pep552 = (PYVERSION >= (3, 7, 0, 'alpha', 4)) |
|
64 |
|
65 # Python 3.7.0b3 changed the behavior of the sys.path[0] entry for -m. It |
|
66 # used to be an empty string (meaning the current directory). It changed |
|
67 # to be the actual path to the current directory, so that os.chdir wouldn't |
|
68 # affect the outcome. |
|
69 actual_syspath0_dash_m = (PYVERSION >= (3, 7, 0, 'beta', 3)) |
33 |
70 |
34 # When a break/continue/return statement in a try block jumps to a finally |
71 # When a break/continue/return statement in a try block jumps to a finally |
35 # block, does the finally block do the break/continue/return (pre-3.8), or |
72 # block, does the finally block do the break/continue/return (pre-3.8), or |
36 # does the finally jump back to the break/continue/return (3.8) to do the |
73 # does the finally jump back to the break/continue/return (3.8) to do the |
37 # work? |
74 # work? |
43 trace_decorated_def = (PYVERSION >= (3, 8)) |
80 trace_decorated_def = (PYVERSION >= (3, 8)) |
44 |
81 |
45 # Are while-true loops optimized into absolute jumps with no loop setup? |
82 # Are while-true loops optimized into absolute jumps with no loop setup? |
46 nix_while_true = (PYVERSION >= (3, 8)) |
83 nix_while_true = (PYVERSION >= (3, 8)) |
47 |
84 |
|
85 # Python 3.9a1 made sys.argv[0] and other reported files absolute paths. |
|
86 report_absolute_files = (PYVERSION >= (3, 9)) |
|
87 |
|
88 # Python 3.9a2 changed how return/finally was traced, but it was |
|
89 # temporary. |
|
90 bpo39114 = (PYVERSION == (3, 9, 0, 'alpha', 2, 0)) |
|
91 |
48 # Coverage.py specifics. |
92 # Coverage.py specifics. |
49 |
93 |
50 # Are we using the C-implemented trace function? |
94 # Are we using the C-implemented trace function? |
51 C_TRACER = os.getenv('COVERAGE_TEST_TRACER', 'c') == 'c' |
95 C_TRACER = os.getenv('COVERAGE_TEST_TRACER', 'c') == 'c' |
52 |
96 |