Skip to content

Commit 3c51217

Browse files
committed
Tweaks in coverage_plugin
1 parent 9814860 commit 3c51217

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

coverage_plugin.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
"""
22
A 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
69
https://coverage.readthedocs.io/en/latest/api_plugin.html
710
https://github.com/cython/cython/blob/master/Cython/Coverage.py
@@ -15,6 +18,7 @@
1518
from pathlib import Path
1619

1720

21+
# Paths used by spin/meson in a src-layout:
1822
root_dir = Path(__file__).parent
1923
build_dir = root_dir / 'build'
2024
build_install_dir = root_dir / 'build-install'
@@ -97,11 +101,10 @@ def parse_cfile_lines(c_file):
97101

98102

99103
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+
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

124127
class 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

Comments
 (0)