Skip to content

Commit 72ba6af

Browse files
Merge pull request #29 from oscarbenjamin/pr_coverage
wip: add coverage testing
2 parents be48b74 + a3b6bc8 commit 72ba6af

File tree

5 files changed

+65
-2
lines changed

5 files changed

+65
-2
lines changed

.coveragerc

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[run]
2+
plugins = Cython.Coverage

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ MANIFEST
1212
.eggs
1313
.local
1414
*.egg-info
15+
.coverage

bin/activate

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export C_INCLUDE_PATH=$(pwd)/.local/include
2+
export LIBRARY_PATH=$(pwd)/.local/lib
3+
export LD_LIBRARY_PATH=$(pwd)/.local/lib
4+
export PYTHONPATH=$(pwd)/src

bin/coverage.sh

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
#
3+
# Note: cython's Cython/Coverage.py fails for pyx files that are included in
4+
# other pyx files. This gives the following error:
5+
#
6+
# $ coverage report -m
7+
# Plugin 'Cython.Coverage.Plugin' did not provide a file reporter for
8+
# '.../python-flint/src/flint/fmpz.pyx'.
9+
#
10+
# A patch to the file is needed:
11+
#
12+
# --- Coverage.py.backup 2022-12-09 17:36:35.387690467 +0000
13+
# +++ Coverage.py 2022-12-09 17:08:06.282516837 +0000
14+
# @@ -172,7 +172,9 @@ class Plugin(CoveragePlugin):
15+
# else:
16+
# c_file, _ = self._find_source_files(filename)
17+
# if not c_file:
18+
# - return None
19+
# + c_file = os.path.join(os.path.dirname(filename), 'pyflint.c')
20+
# + if not os.path.exists(c_file):
21+
# + return None
22+
# rel_file_path, code = self._read_source_lines(c_file, filename)
23+
# if code is None:
24+
# return None # no source found
25+
#
26+
#
27+
28+
set -o errexit
29+
30+
source bin/activate
31+
32+
export PYTHON_FLINT_COVERAGE=true
33+
34+
python setup.py build_ext --inplace
35+
36+
coverage run test/test.py
37+
coverage run --append test/dtest.py
38+
39+
coverage report -m
40+
coverage html

setup.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
from distutils.core import setup
66
from distutils.extension import Extension
77
from Cython.Distutils import build_ext
8+
from Cython.Build import cythonize
89
from numpy.distutils.system_info import default_include_dirs, default_lib_dirs
910

1011
from distutils.sysconfig import get_config_vars
1112

13+
1214
if sys.platform == 'win32':
1315
#
1416
# This is used in CI to build wheels with mingw64
@@ -36,16 +38,30 @@
3638
(opt,) = get_config_vars('OPT')
3739
os.environ['OPT'] = " ".join(flag for flag in opt.split() if flag != '-Wstrict-prototypes')
3840

41+
3942
default_include_dirs += [
4043
os.path.join(d, "flint") for d in default_include_dirs
4144
]
4245

46+
47+
define_macros = []
48+
compiler_directives = {'language_level':2}
49+
50+
51+
# Enable coverage tracing
52+
if os.getenv('PYTHON_FLINT_COVERAGE'):
53+
define_macros.append(('CYTHON_TRACE', 1))
54+
compiler_directives['linetrace'] = True
55+
56+
4357
ext_modules = [
4458
Extension(
4559
"flint._flint", ["src/flint/pyflint.pyx"],
4660
libraries=libraries,
4761
library_dirs=default_lib_dirs,
48-
include_dirs=default_include_dirs)
62+
include_dirs=default_include_dirs,
63+
define_macros=define_macros,
64+
)
4965
]
5066

5167
for e in ext_modules:
@@ -54,7 +70,7 @@
5470
setup(
5571
name='python-flint',
5672
cmdclass={'build_ext': build_ext},
57-
ext_modules=ext_modules,
73+
ext_modules=cythonize(ext_modules, compiler_directives=compiler_directives),
5874
packages=['flint'],
5975
package_dir={'': 'src'},
6076
description='Bindings for FLINT and Arb',

0 commit comments

Comments
 (0)