1616from coverage .misc import isolate_module
1717from coverage .pytracer import PyTracer
1818from coverage .sysmon import SysMonitor
19- from coverage .types import TFileDisposition , Tracer , TWarnFn
19+ from coverage .types import TDebugCtl , TFileDisposition , Tracer , TWarnFn
2020
2121os = isolate_module (os )
2222
@@ -56,17 +56,18 @@ class Core:
5656
5757 def __init__ (
5858 self ,
59+ * ,
5960 warn : TWarnFn ,
61+ debug : TDebugCtl | None ,
6062 config : CoverageConfig ,
6163 dynamic_contexts : bool ,
6264 metacov : bool ,
6365 ) -> None :
64- # print("core.py!!!")
65- # print(f"sys.path = {newline}{newline.join(sys.path)}")
66- # print(f"{CTRACER_FILE = }")
67- # import inspect
68- #
69- # print("\n".join("%30s : %s:%d" % (t[3], t[1], t[2]) for t in inspect.stack()[99:0:-1]))
66+ def _debug (msg : str ) -> None :
67+ if debug :
68+ debug .write (msg )
69+
70+ _debug ("in core.py" )
7071
7172 # Check the conditions that preclude us from using sys.monitoring.
7273 reason_no_sysmon = ""
@@ -82,31 +83,34 @@ def __init__(
8283 core_name : str | None = None
8384 if config .timid :
8485 core_name = "pytrace"
85- # print ("core.py: Using pytrace because timid=True")
86+ _debug ("core.py: Using pytrace because timid=True" )
8687 elif core_name is None :
8788 # This could still leave core_name as None.
8889 core_name = config .core
89- # print (f"core.py: core from config is {core_name!r}")
90+ _debug (f"core.py: core from config is { core_name !r} " )
9091
9192 if core_name == "sysmon" and reason_no_sysmon :
93+ _debug (f"core.py: raising ConfigError because sysmon not usable: { reason_no_sysmon } " )
9294 raise ConfigError (
9395 f"Can't use core=sysmon: sys.monitoring { reason_no_sysmon } " , skip_tests = True
9496 )
9597
9698 if core_name is None :
9799 if env .SYSMON_DEFAULT and not reason_no_sysmon :
98100 core_name = "sysmon"
99- # print ("core.py: Using sysmon because SYSMON_DEFAULT is set")
101+ _debug ("core.py: Using sysmon because SYSMON_DEFAULT is set" )
100102 else :
101103 core_name = "ctrace"
102- # print ("core.py: Defaulting to ctrace core")
104+ _debug ("core.py: Defaulting to ctrace core" )
103105
104106 if core_name == "ctrace" :
105107 if not CTRACER_FILE :
106108 if IMPORT_ERROR and env .SHIPPING_WHEELS :
107109 warn (f"Couldn't import C tracer: { IMPORT_ERROR } " , slug = "no-ctracer" , once = True )
108110 core_name = "pytrace"
109- # print("core.py: Falling back to pytrace because C tracer not available")
111+ _debug ("core.py: Falling back to pytrace because C tracer not available" )
112+
113+ _debug (f"core.py: Using core={ core_name } " )
110114
111115 self .tracer_kwargs = {}
112116
0 commit comments