11"""
22A Cython plugin for coverage.py suitable for a spin/meson project.
33
4- This is derived from Cython's coverage plugin.
4+ This follows the same general approach as Cython's coverage plugin and uses the
5+ Cython plugin for parsing the C files. The difference here is that files are
6+ laid out very differently in a meson project. Assuming meson makes it a lot
7+ easier to find all the C files because we can just parse the build.ninja file.
58
69https://coverage.readthedocs.io/en/latest/api_plugin.html
710https://github.com/cython/cython/blob/master/Cython/Coverage.py
1518from pathlib import Path
1619
1720
21+ # Paths used by spin/meson in a src-layout:
1822root_dir = Path (__file__ ).parent
1923build_dir = root_dir / 'build'
2024build_install_dir = root_dir / 'build-install'
@@ -97,11 +101,10 @@ def parse_cfile_lines(c_file):
97101
98102
99103class Plugin (CoveragePlugin ):
100- """
101- A Cython coverage plugin for coverage.py suitable for a spin/meson project.
102- """
104+ """A coverage plugin for a spin/meson project with Cython code."""
105+
103106 def file_tracer (self , filename ):
104- """Find a tracer for filename as reported in trace events."""
107+ """Find a tracer for filename to handle trace events."""
105108 path = Path (filename )
106109
107110 if path .suffix in ('.pyx' , '.pxd' ) and root_dir in path .parents :
@@ -122,7 +125,7 @@ def file_reporter(self, filename):
122125
123126
124127class CyFileTracer (FileTracer ):
125- """File tracer for Cython or Python files (.pyx,.pxd,.py )."""
128+ """File tracer for Cython files (.pyx,.pxd)."""
126129
127130 def __init__ (self , srcpath ):
128131 assert (src_dir / srcpath ).exists ()
@@ -136,7 +139,7 @@ def has_dynamic_source_filename(self):
136139
137140 def dynamic_source_filename (self , filename , frame ):
138141 """Get filename from frame and return abspath to file."""
139- # What is returned here needs to match MyFileReporter .filename
142+ # What is returned here needs to match CyFileReporter .filename
140143 path = frame .f_code .co_filename
141144 return self .get_source_filename (path )
142145
@@ -159,11 +162,9 @@ def __init__(self, srcpath):
159162 assert abspath .exists ()
160163
161164 # filepath here needs to match dynamic_source_filename
162- filepath = str (abspath )
163- super ().__init__ (filepath )
165+ super ().__init__ (str (abspath ))
164166
165167 self .srcpath = srcpath
166- self .abspath = abspath
167168
168169 def relative_filename (self ):
169170 """Path displayed in the coverage reports."""
0 commit comments