1
1
"""
2
2
A Cython plugin for coverage.py suitable for a spin/meson project.
3
3
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.
5
8
6
9
https://coverage.readthedocs.io/en/latest/api_plugin.html
7
10
https://github.com/cython/cython/blob/master/Cython/Coverage.py
15
18
from pathlib import Path
16
19
17
20
21
+ # Paths used by spin/meson in a src-layout:
18
22
root_dir = Path (__file__ ).parent
19
23
build_dir = root_dir / 'build'
20
24
build_install_dir = root_dir / 'build-install'
@@ -97,11 +101,10 @@ def parse_cfile_lines(c_file):
97
101
98
102
99
103
class 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
+
103
106
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."""
105
108
path = Path (filename )
106
109
107
110
if path .suffix in ('.pyx' , '.pxd' ) and root_dir in path .parents :
@@ -122,7 +125,7 @@ def file_reporter(self, filename):
122
125
123
126
124
127
class CyFileTracer (FileTracer ):
125
- """File tracer for Cython or Python files (.pyx,.pxd,.py )."""
128
+ """File tracer for Cython files (.pyx,.pxd)."""
126
129
127
130
def __init__ (self , srcpath ):
128
131
assert (src_dir / srcpath ).exists ()
@@ -136,7 +139,7 @@ def has_dynamic_source_filename(self):
136
139
137
140
def dynamic_source_filename (self , filename , frame ):
138
141
"""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
140
143
path = frame .f_code .co_filename
141
144
return self .get_source_filename (path )
142
145
@@ -159,11 +162,9 @@ def __init__(self, srcpath):
159
162
assert abspath .exists ()
160
163
161
164
# filepath here needs to match dynamic_source_filename
162
- filepath = str (abspath )
163
- super ().__init__ (filepath )
165
+ super ().__init__ (str (abspath ))
164
166
165
167
self .srcpath = srcpath
166
- self .abspath = abspath
167
168
168
169
def relative_filename (self ):
169
170
"""Path displayed in the coverage reports."""
0 commit comments