|
10 | 10 | from typing import Any
|
11 | 11 |
|
12 | 12 | from coverage import env
|
| 13 | +from coverage.config import CoverageConfig |
13 | 14 | from coverage.disposition import FileDisposition
|
14 | 15 | from coverage.exceptions import ConfigError
|
15 | 16 | from coverage.misc import isolate_module
|
16 | 17 | from coverage.pytracer import PyTracer
|
17 | 18 | from coverage.sysmon import SysMonitor
|
18 | 19 | from coverage.types import (
|
19 | 20 | TFileDisposition,
|
20 |
| - Tracer, |
21 | 21 | TWarnFn,
|
| 22 | + Tracer, |
22 | 23 | )
|
23 | 24 |
|
24 | 25 |
|
@@ -52,36 +53,47 @@ class Core:
|
52 | 53 | packed_arcs: bool
|
53 | 54 | systrace: bool
|
54 | 55 |
|
55 |
| - def __init__(self, |
| 56 | + def __init__( |
| 57 | + self, |
56 | 58 | warn: TWarnFn,
|
57 |
| - timid: bool, |
| 59 | + config: CoverageConfig, |
| 60 | + dynamic_contexts: bool, |
58 | 61 | metacov: bool,
|
59 | 62 | ) -> None:
|
60 |
| - # Defaults |
61 |
| - self.tracer_kwargs = {} |
| 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" |
62 | 71 |
|
63 |
| - core_name: str | None |
64 |
| - if timid: |
| 72 | + core_name: str | None = None |
| 73 | + if config.timid: |
65 | 74 | core_name = "pytrace"
|
66 |
| - else: |
| 75 | + |
| 76 | + if core_name is None: |
67 | 77 | core_name = os.getenv("COVERAGE_CORE")
|
68 | 78 |
|
69 |
| - if core_name == "sysmon" and not env.PYBEHAVIOR.pep669: |
70 |
| - warn("sys.monitoring isn't available, using default core", slug="no-sysmon") |
71 |
| - core_name = None |
| 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 | + # Someday we will default to sysmon, but it's still experimental: |
| 85 | + # if not reason_no_sysmon: |
| 86 | + # core_name = "sysmon" |
| 87 | + if HAS_CTRACER: |
| 88 | + core_name = "ctrace" |
| 89 | + else: |
| 90 | + core_name = "pytrace" |
72 | 91 |
|
73 |
| - if not core_name: |
74 |
| - # Once we're comfortable with sysmon as a default: |
75 |
| - # if env.PYBEHAVIOR.pep669 and self.should_start_context is None: |
76 |
| - # core_name = "sysmon" |
77 |
| - if HAS_CTRACER: |
78 |
| - core_name = "ctrace" |
79 |
| - else: |
80 |
| - core_name = "pytrace" |
| 92 | + self.tracer_kwargs = {} |
81 | 93 |
|
82 | 94 | if core_name == "sysmon":
|
83 | 95 | self.tracer_class = SysMonitor
|
84 |
| - self.tracer_kwargs = {"tool_id": 3 if metacov else 1} |
| 96 | + self.tracer_kwargs["tool_id"] = 3 if metacov else 1 |
85 | 97 | self.file_disposition_class = FileDisposition
|
86 | 98 | self.supports_plugins = False
|
87 | 99 | self.packed_arcs = False
|
|
0 commit comments