|
18 | 18 | from coverage.sysmon import SysMonitor
|
19 | 19 | from coverage.types import (
|
20 | 20 | TFileDisposition,
|
21 |
| - Tracer, |
22 | 21 | TWarnFn,
|
| 22 | + Tracer, |
23 | 23 | )
|
24 | 24 |
|
25 | 25 |
|
@@ -53,36 +53,40 @@ class Core:
|
53 | 53 | packed_arcs: bool
|
54 | 54 | systrace: bool
|
55 | 55 |
|
56 |
| - def __init__(self, warn: TWarnFn, config: CoverageConfig, metacov: bool) -> None: |
57 |
| - core_name: str | None |
| 56 | + def __init__( |
| 57 | + self, |
| 58 | + warn: TWarnFn, |
| 59 | + config: CoverageConfig, |
| 60 | + dynamic_contexts: bool, |
| 61 | + metacov: bool, |
| 62 | + ) -> None: |
| 63 | + # Check the conditions that preclude us from using sys.monitoring. |
| 64 | + reason_no_sysmon = "" |
| 65 | + if not env.PYBEHAVIOR.pep669: |
| 66 | + reason_no_sysmon = "isn't available in this version" |
| 67 | + elif config.branch and not env.PYBEHAVIOR.branch_right_left: |
| 68 | + reason_no_sysmon = "can't measure branches in this version" |
| 69 | + elif dynamic_contexts: |
| 70 | + reason_no_sysmon = "doesn't yet support dynamic contexts" |
| 71 | + |
| 72 | + core_name: str | None = None |
58 | 73 | if config.timid:
|
59 | 74 | core_name = "pytrace"
|
60 |
| - else: |
| 75 | + |
| 76 | + if core_name is None: |
61 | 77 | core_name = os.getenv("COVERAGE_CORE")
|
62 | 78 |
|
63 |
| - if core_name == "sysmon": |
64 |
| - if not env.PYBEHAVIOR.pep669: |
65 |
| - warn( |
66 |
| - "sys.monitoring isn't available in this version, using default core", |
67 |
| - slug="no-sysmon", |
68 |
| - ) |
69 |
| - core_name = None |
70 |
| - |
71 |
| - if config.branch and not env.PYBEHAVIOR.branch_right_left: |
72 |
| - warn( |
73 |
| - "sys.monitoring can't measure branches in this vesion, using default core", |
74 |
| - slug="no-sysmon", |
75 |
| - ) |
76 |
| - core_name = None |
77 |
| - |
78 |
| - if not core_name: |
79 |
| - # Once we're comfortable with sysmon as a default: |
80 |
| - # if env.PYBEHAVIOR.pep669 and self.should_start_context is None: |
81 |
| - # core_name = "sysmon" |
82 |
| - if HAS_CTRACER: |
83 |
| - core_name = "ctrace" |
84 |
| - else: |
85 |
| - core_name = "pytrace" |
| 79 | + if core_name == "sysmon" and reason_no_sysmon: |
| 80 | + warn(f"sys.monitoring {reason_no_sysmon}, using default core", slug="no-sysmon") |
| 81 | + core_name = None |
| 82 | + |
| 83 | + if core_name is None: |
| 84 | + if not reason_no_sysmon: |
| 85 | + core_name = "sysmon" |
| 86 | + elif HAS_CTRACER: |
| 87 | + core_name = "ctrace" |
| 88 | + else: |
| 89 | + core_name = "pytrace" |
86 | 90 |
|
87 | 91 | self.tracer_kwargs = {}
|
88 | 92 |
|
|
0 commit comments