Skip to content

Commit bbf7461

Browse files
committed
wip: no stack, works better
1 parent 3e96647 commit bbf7461

File tree

6 files changed

+360
-17
lines changed

6 files changed

+360
-17
lines changed

coverage/collector.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from coverage.disposition import FileDisposition
2222
from coverage.exceptions import ConfigError
2323
from coverage.misc import human_sorted_items, isolate_module
24+
from coverage.pep669_tracer import Pep669Tracer
2425
from coverage.plugin import CoveragePlugin
2526
from coverage.pytracer import PyTracer
2627
from coverage.types import (
@@ -144,17 +145,24 @@ def __init__(
144145
if HAS_CTRACER and not timid:
145146
use_ctracer = True
146147

147-
#if HAS_CTRACER and self._trace_class is CTracer:
148-
if use_ctracer:
148+
if env.PYBEHAVIOR.pep669 and self.should_start_context is None:
149+
self._trace_class = Pep669Tracer
150+
self.file_disposition_class = FileDisposition
151+
self.supports_plugins = False
152+
self.packed_arcs = False
153+
self.systrace = False
154+
elif use_ctracer:
149155
self._trace_class = CTracer
150156
self.file_disposition_class = CFileDisposition
151157
self.supports_plugins = True
152158
self.packed_arcs = True
159+
self.systrace = True
153160
else:
154161
self._trace_class = PyTracer
155162
self.file_disposition_class = FileDisposition
156163
self.supports_plugins = False
157164
self.packed_arcs = False
165+
self.systrace = True
158166

159167
# We can handle a few concurrency options here, but only one at a time.
160168
concurrencies = set(self.concurrency)
@@ -275,6 +283,7 @@ def reset(self) -> None:
275283

276284
def _start_tracer(self) -> TTraceFn:
277285
"""Start a new Tracer object, and store it in self.tracers."""
286+
# TODO: for pep669, this doesn't return a TTraceFn
278287
tracer = self._trace_class()
279288
tracer.data = self.data
280289
tracer.trace_arcs = self.branch
@@ -344,7 +353,7 @@ def start(self) -> None:
344353

345354
# Install our installation tracer in threading, to jump-start other
346355
# threads.
347-
if self.threading:
356+
if self.systrace and self.threading:
348357
self.threading.settrace(self._installation_trace)
349358

350359
def stop(self) -> None:

coverage/debug.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def exc_one_line(exc: Exception) -> str:
181181
return "|".join(l.rstrip() for l in lines)
182182

183183

184-
def short_stack(limit: Optional[int] = None, skip: int = 0) -> str:
184+
def short_stack(limit: Optional[int] = None, skip: int = 0, full: bool = False) -> str:
185185
"""Return a string summarizing the call stack.
186186
187187
The string is multi-line, with one line per stack frame. Each line shows
@@ -209,11 +209,12 @@ def short_stack(limit: Optional[int] = None, skip: int = 0) -> str:
209209
]
210210

211211
stack: Iterable[inspect.FrameInfo] = inspect.stack()[limit:skip:-1]
212-
for pat in BORING_PRELUDE:
213-
stack = itertools.dropwhile(
214-
(lambda fi, pat=pat: re.search(pat, fi.filename)), # type: ignore[misc]
215-
stack
216-
)
212+
if not full:
213+
for pat in BORING_PRELUDE:
214+
stack = itertools.dropwhile(
215+
(lambda fi, pat=pat: re.search(pat, fi.filename)), # type: ignore[misc]
216+
stack
217+
)
217218
return "\n".join(f"{fi.function:>30s} : {fi.filename}:{fi.lineno}" for fi in stack)
218219

219220

coverage/env.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ class PYBEHAVIOR:
113113
# Changed in https://github.com/python/cpython/pull/101441
114114
comprehensions_are_functions = (PYVERSION <= (3, 12, 0, "alpha", 7, 0))
115115

116+
# PEP669 Low Impact Monitoring: https://peps.python.org/pep-0669/
117+
pep669 = bool(getattr(sys, "monitoring", None))
118+
119+
116120
# Coverage.py specifics.
117121

118122
# Are we using the C-implemented trace function?

0 commit comments

Comments
 (0)