eric7/DebugClients/Python/coverage/env.py

branch
eric7
changeset 8775
0802ae193343
parent 8527
2bd1325d727e
child 8929
fcca2fa618bf
equal deleted inserted replaced
8774:d728227e8ebb 8775:0802ae193343
18 IRONPYTHON = (platform.python_implementation() == "IronPython") 18 IRONPYTHON = (platform.python_implementation() == "IronPython")
19 19
20 # Python versions. We amend version_info with one more value, a zero if an 20 # Python versions. We amend version_info with one more value, a zero if an
21 # official version, or 1 if built from source beyond an official version. 21 # official version, or 1 if built from source beyond an official version.
22 PYVERSION = sys.version_info + (int(platform.python_version()[-1] == "+"),) 22 PYVERSION = sys.version_info + (int(platform.python_version()[-1] == "+"),)
23 PY2 = PYVERSION < (3, 0)
24 PY3 = PYVERSION >= (3, 0)
25 23
26 if PYPY: 24 if PYPY:
27 PYPYVERSION = sys.pypy_version_info 25 PYPYVERSION = sys.pypy_version_info
28 26
29 PYPY2 = PYPY and PY2
30 PYPY3 = PYPY and PY3
31
32 # Python behavior. 27 # Python behavior.
33 class PYBEHAVIOR(object): 28 class PYBEHAVIOR:
34 """Flags indicating this Python's behavior.""" 29 """Flags indicating this Python's behavior."""
35 30
31 # Does Python conform to PEP626, Precise line numbers for debugging and other tools.
32 # https://www.python.org/dev/peps/pep-0626
36 pep626 = CPYTHON and (PYVERSION > (3, 10, 0, 'alpha', 4)) 33 pep626 = CPYTHON and (PYVERSION > (3, 10, 0, 'alpha', 4))
37 34
38 # Is "if __debug__" optimized away? 35 # Is "if __debug__" optimized away?
39 if PYPY3: 36 if PYPY:
40 optimize_if_debug = True 37 optimize_if_debug = True
41 elif PYPY2:
42 optimize_if_debug = False
43 else: 38 else:
44 optimize_if_debug = not pep626 39 optimize_if_debug = not pep626
45 40
46 # Is "if not __debug__" optimized away? 41 # Is "if not __debug__" optimized away?
47 optimize_if_not_debug = (not PYPY) and (PYVERSION >= (3, 7, 0, 'alpha', 4)) 42 optimize_if_not_debug = (not PYPY) and (PYVERSION >= (3, 7, 0, 'alpha', 4))
48 if pep626: 43 if pep626:
49 optimize_if_not_debug = False 44 optimize_if_not_debug = False
50 if PYPY3: 45 if PYPY:
51 optimize_if_not_debug = True 46 optimize_if_not_debug = True
52 47
53 # Is "if not __debug__" optimized away even better? 48 # Is "if not __debug__" optimized away even better?
54 optimize_if_not_debug2 = (not PYPY) and (PYVERSION >= (3, 8, 0, 'beta', 1)) 49 optimize_if_not_debug2 = (not PYPY) and (PYVERSION >= (3, 8, 0, 'beta', 1))
55 if pep626: 50 if pep626:
56 optimize_if_not_debug2 = False 51 optimize_if_not_debug2 = False
57 52
58 # Do we have yield-from? 53 # Yet another way to optimize "if not __debug__"?
59 yield_from = (PYVERSION >= (3, 3)) 54 optimize_if_not_debug3 = (PYPY and PYVERSION >= (3, 8))
60
61 # Do we have PEP 420 namespace packages?
62 namespaces_pep420 = (PYVERSION >= (3, 3))
63
64 # Do .pyc files have the source file size recorded in them?
65 size_in_pyc = (PYVERSION >= (3, 3))
66
67 # Do we have async and await syntax?
68 async_syntax = (PYVERSION >= (3, 5))
69
70 # PEP 448 defined additional unpacking generalizations
71 unpackings_pep448 = (PYVERSION >= (3, 5))
72 55
73 # Can co_lnotab have negative deltas? 56 # Can co_lnotab have negative deltas?
74 negative_lnotab = (PYVERSION >= (3, 6)) and not (PYPY and PYPYVERSION < (7, 2)) 57 negative_lnotab = not (PYPY and PYPYVERSION < (7, 2))
75 58
76 # Do .pyc files conform to PEP 552? Hash-based pyc's. 59 # Do .pyc files conform to PEP 552? Hash-based pyc's.
77 hashed_pyc_pep552 = (PYVERSION >= (3, 7, 0, 'alpha', 4)) 60 hashed_pyc_pep552 = (PYVERSION >= (3, 7, 0, 'alpha', 4))
78 61
79 # Python 3.7.0b3 changed the behavior of the sys.path[0] entry for -m. It 62 # Python 3.7.0b3 changed the behavior of the sys.path[0] entry for -m. It
80 # used to be an empty string (meaning the current directory). It changed 63 # used to be an empty string (meaning the current directory). It changed
81 # to be the actual path to the current directory, so that os.chdir wouldn't 64 # to be the actual path to the current directory, so that os.chdir wouldn't
82 # affect the outcome. 65 # affect the outcome.
83 actual_syspath0_dash_m = CPYTHON and (PYVERSION >= (3, 7, 0, 'beta', 3)) 66 actual_syspath0_dash_m = (
67 (CPYTHON and (PYVERSION >= (3, 7, 0, 'beta', 3))) or
68 (PYPY and (PYPYVERSION >= (7, 3, 4)))
69 )
84 70
85 # 3.7 changed how functions with only docstrings are numbered. 71 # 3.7 changed how functions with only docstrings are numbered.
86 docstring_only_function = (not PYPY) and ((3, 7, 0, 'beta', 5) <= PYVERSION <= (3, 10)) 72 docstring_only_function = (not PYPY) and ((3, 7, 0, 'beta', 5) <= PYVERSION <= (3, 10))
87 73
88 # When a break/continue/return statement in a try block jumps to a finally 74 # When a break/continue/return statement in a try block jumps to a finally
92 finally_jumps_back = ((3, 8) <= PYVERSION < (3, 10)) 78 finally_jumps_back = ((3, 8) <= PYVERSION < (3, 10))
93 79
94 # When a function is decorated, does the trace function get called for the 80 # When a function is decorated, does the trace function get called for the
95 # @-line and also the def-line (new behavior in 3.8)? Or just the @-line 81 # @-line and also the def-line (new behavior in 3.8)? Or just the @-line
96 # (old behavior)? 82 # (old behavior)?
97 trace_decorated_def = (PYVERSION >= (3, 8)) 83 trace_decorated_def = (CPYTHON and PYVERSION >= (3, 8))
98 84
99 # Are while-true loops optimized into absolute jumps with no loop setup? 85 # Are while-true loops optimized into absolute jumps with no loop setup?
100 nix_while_true = (PYVERSION >= (3, 8)) 86 nix_while_true = (PYVERSION >= (3, 8))
101 87
102 # Python 3.9a1 made sys.argv[0] and other reported files absolute paths. 88 # Python 3.9a1 made sys.argv[0] and other reported files absolute paths.
114 module_firstline_1 = pep626 100 module_firstline_1 = pep626
115 101
116 # Are "if 0:" lines (and similar) kept in the compiled code? 102 # Are "if 0:" lines (and similar) kept in the compiled code?
117 keep_constant_test = pep626 103 keep_constant_test = pep626
118 104
105 # When leaving a with-block, do we visit the with-line again for the exit?
106 exit_through_with = (PYVERSION >= (3, 10, 0, 'beta'))
107
108 # Match-case construct.
109 match_case = (PYVERSION >= (3, 10))
110
111 # Some words are keywords in some places, identifiers in other places.
112 soft_keywords = (PYVERSION >= (3, 10))
113
114
119 # Coverage.py specifics. 115 # Coverage.py specifics.
120 116
121 # Are we using the C-implemented trace function? 117 # Are we using the C-implemented trace function?
122 C_TRACER = os.getenv('COVERAGE_TEST_TRACER', 'c') == 'c' 118 C_TRACER = os.getenv('COVERAGE_TEST_TRACER', 'c') == 'c'
123 119
126 122
127 # Are we running our test suite? 123 # Are we running our test suite?
128 # Even when running tests, you can use COVERAGE_TESTING=0 to disable the 124 # Even when running tests, you can use COVERAGE_TESTING=0 to disable the
129 # test-specific behavior like contracts. 125 # test-specific behavior like contracts.
130 TESTING = os.getenv('COVERAGE_TESTING', '') == 'True' 126 TESTING = os.getenv('COVERAGE_TESTING', '') == 'True'
127
128 # Environment COVERAGE_NO_CONTRACTS=1 can turn off contracts while debugging
129 # tests to remove noise from stack traces.
130 # $set_env.py: COVERAGE_NO_CONTRACTS - Disable PyContracts to simplify stack traces.
131 USE_CONTRACTS = TESTING and not bool(int(os.environ.get("COVERAGE_NO_CONTRACTS", 0)))

eric ide

mercurial