Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9f0c046

Browse files
committedJan 24, 2025·
ci: add code coverage of cython files
1 parent f60e919 commit 9f0c046

File tree

4 files changed

+117
-17
lines changed

4 files changed

+117
-17
lines changed
 

‎.github/workflows/tests.yml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010

1111
env:
1212
POETRY_VERSION: 1.8
13+
CYTHON_TRACE: 1 # for code coverage
1314

1415
jobs:
1516
testing:

‎build.py

+23-5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ def with_patches():
4949
if retcode != 0:
5050
raise RuntimeError(f"Failed to reset submodules: {command}")
5151

52+
compiler_directives = {
53+
"language_level": "3",
54+
'embedsignature': True,
55+
}
5256
SOURCE_DIR = Path("pybwa")
5357
BUILD_DIR = Path("cython_build")
5458
compile_args = []
@@ -62,20 +66,34 @@ def with_patches():
6266
define_macros = [("HAVE_PTHREAD", None), ("USE_MALLOC_WRAPPERS", None)]
6367
h_files = []
6468
c_files = []
69+
70+
exclude_files = {
71+
"pybwa": ["libbwaaln.c", "libbwaindex.c", "libbwamem.c"],
72+
"bwa": ['example.c', 'main.c']
73+
}
6574
for root_dir in library_dirs:
6675
h_files.extend(str(x) for x in Path(root_dir).rglob("*.h"))
67-
c_files.extend(str(x) for x in Path(root_dir).rglob("*.c") if x.name not in ['example.c', 'main.c'])
76+
c_files.extend(str(x) for x in Path(root_dir).rglob("*.c") if x.name not in exclude_files[root_dir])
77+
78+
# Check if we should build with linetracing for coverage
79+
build_with_coverage = os.environ.get("CYTHON_TRACE", "false").lower() in ("1", "true", '"true"')
80+
if build_with_coverage:
81+
compiler_directives["linetrace"] = True
82+
compiler_directives['emit_code_comments'] = True
83+
define_macros.extend([('CYTHON_TRACE', 1), ('CYTHON_TRACE_NOGIL', 1), ('DCYTHON_USE_SYS_MONITORING', 0)])
84+
BUILD_DIR = Path(".") # the compiled .c files need to be next to the .pyx files for coverage
6885

6986
if platform.system() != 'Windows':
70-
compile_args = [
87+
compile_args.extend([
7188
"-Wno-unused-result",
7289
"-Wno-unreachable-code",
7390
"-Wno-single-bit-bitfield-constant-conversion",
7491
"-Wno-deprecated-declarations",
7592
"-Wno-unused",
7693
"-Wno-strict-prototypes",
7794
"-Wno-sign-compare",
78-
"-Wno-error=declaration-after-statement"]
95+
"-Wno-error=declaration-after-statement"
96+
])
7997

8098
libbwaindex_module = Extension(
8199
name='pybwa.libbwaindex',
@@ -135,8 +153,8 @@ def cythonize_helper(extension_modules: List[Extension]) -> List[Extension]:
135153
# Parallelize our build
136154
nthreads=multiprocessing.cpu_count() * 2,
137155

138-
# Tell Cython we're using Python 3. Becomes default in Cython 3
139-
compiler_directives={"language_level": "3", 'embedsignature': True},
156+
# Compiler directives (e.g. language, or line tracing for coverage)
157+
compiler_directives=compiler_directives,
140158

141159
# (Optional) Always rebuild, even if files untouched
142160
force=True,

‎poetry.lock

+87-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pyproject.toml

+6
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ pytest-cov = ">=2.8.1"
5555
ruff = "0.4.8"
5656
setuptools = ">=68.0.0"
5757
black = ">=24.8.0" # for readthedocs
58+
cython = "^3.0.11"
59+
coverage = {extras = ["toml"], version = "^7.6.10"}
5860

5961
[tool.poetry.group.docs.dependencies]
6062
# dependencies for building docs
@@ -98,3 +100,7 @@ warn_unused_configs = true
98100
warn_unused_ignores = true
99101
enable_error_code = "ignore-without-code"
100102
exclude = ["site/", "docs/"]
103+
104+
[tool.coverage.run]
105+
plugins = ["Cython.Coverage"]
106+
branch = true

0 commit comments

Comments
 (0)
Please sign in to comment.