Skip to content

Commit d035f10

Browse files
committed
Compile with coverage support optionally
1 parent e3bb928 commit d035f10

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[build-system]
22
requires = ["setuptools>=51", "cython>=0.29", "wheel"]
33
build-backend = "setuptools.build_meta"
4+
5+
[tool.coverage.run]
6+
plugins = ["Cython.Coverage"]

setup.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import tempfile
2626
from pathlib import Path
2727

28+
from Cython.Build import cythonize
29+
2830
from setuptools import Extension, find_packages, setup
2931
from setuptools.command.build_ext import build_ext
3032

@@ -62,6 +64,17 @@ def build_extension(self, ext):
6264
ext.extra_objects = [
6365
os.path.join(isa_l_prefix_dir, "lib", "libisal.a")]
6466

67+
if os.getenv("CYTHON_COVERAGE") is not None:
68+
# Add cython directives and macros for coverage support.
69+
cythonized_exts = cythonize(ext, compiler_directives=dict(
70+
linetrace=True
71+
))
72+
for cython_ext in cythonized_exts:
73+
cython_ext.define_macros = [("CYTHON_TRACE_NOGIL", "1")]
74+
cython_ext._needs_stub = False
75+
super().build_extension(cython_ext)
76+
return
77+
6578
super().build_extension(ext)
6679

6780

tox.ini

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
# python3 interpreter of the user.
44
envlist=py3
55
[testenv]
6-
deps=coverage
6+
deps=coverage[toml]
7+
cython
78
pytest
89
passenv=
910
PYTHON_ISAL_LINK_DYNAMIC
11+
setenv=
12+
CYTHON_COVERAGE=true
1013
commands =
1114
# Create HTML coverage report for humans and xml coverage report for external services.
1215
coverage run --source={envsitepackagesdir}/isal -m py.test -v tests

0 commit comments

Comments
 (0)