Skip to content

Commit

Permalink
ci: add code coverage of cython files (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
nh13 authored Jan 24, 2025
1 parent f60e919 commit ff67435
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 17 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:

env:
POETRY_VERSION: 1.8
CYTHON_TRACE: 1 # for code coverage

jobs:
testing:
Expand Down
28 changes: 23 additions & 5 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ def with_patches():
if retcode != 0:
raise RuntimeError(f"Failed to reset submodules: {command}")

compiler_directives = {
"language_level": "3",
'embedsignature': True,
}
SOURCE_DIR = Path("pybwa")
BUILD_DIR = Path("cython_build")
compile_args = []
Expand All @@ -62,20 +66,34 @@ def with_patches():
define_macros = [("HAVE_PTHREAD", None), ("USE_MALLOC_WRAPPERS", None)]
h_files = []
c_files = []

exclude_files = {
"pybwa": ["libbwaaln.c", "libbwaindex.c", "libbwamem.c"],
"bwa": ['example.c', 'main.c']
}
for root_dir in library_dirs:
h_files.extend(str(x) for x in Path(root_dir).rglob("*.h"))
c_files.extend(str(x) for x in Path(root_dir).rglob("*.c") if x.name not in ['example.c', 'main.c'])
c_files.extend(str(x) for x in Path(root_dir).rglob("*.c") if x.name not in exclude_files[root_dir])

# Check if we should build with linetracing for coverage
build_with_coverage = os.environ.get("CYTHON_TRACE", "false").lower() in ("1", "true", '"true"')
if build_with_coverage:
compiler_directives["linetrace"] = True
compiler_directives['emit_code_comments'] = True
define_macros.extend([('CYTHON_TRACE', 1), ('CYTHON_TRACE_NOGIL', 1), ('DCYTHON_USE_SYS_MONITORING', 0)])
BUILD_DIR = Path(".") # the compiled .c files need to be next to the .pyx files for coverage

if platform.system() != 'Windows':
compile_args = [
compile_args.extend([
"-Wno-unused-result",
"-Wno-unreachable-code",
"-Wno-single-bit-bitfield-constant-conversion",
"-Wno-deprecated-declarations",
"-Wno-unused",
"-Wno-strict-prototypes",
"-Wno-sign-compare",
"-Wno-error=declaration-after-statement"]
"-Wno-error=declaration-after-statement"
])

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

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

# (Optional) Always rebuild, even if files untouched
force=True,
Expand Down
99 changes: 87 additions & 12 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ pytest-cov = ">=2.8.1"
ruff = "0.4.8"
setuptools = ">=68.0.0"
black = ">=24.8.0" # for readthedocs
cython = "^3.0.11"
coverage = {extras = ["toml"], version = "^7.6.10"}

[tool.poetry.group.docs.dependencies]
# dependencies for building docs
Expand Down Expand Up @@ -98,3 +100,7 @@ warn_unused_configs = true
warn_unused_ignores = true
enable_error_code = "ignore-without-code"
exclude = ["site/", "docs/"]

[tool.coverage.run]
plugins = ["Cython.Coverage"]
branch = true

0 comments on commit ff67435

Please sign in to comment.