Skip to content

wip: add coverage testing #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[run]
plugins = Cython.Coverage
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ MANIFEST
.eggs
.local
*.egg-info
.coverage
4 changes: 4 additions & 0 deletions bin/activate
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export C_INCLUDE_PATH=$(pwd)/.local/include
export LIBRARY_PATH=$(pwd)/.local/lib
export LD_LIBRARY_PATH=$(pwd)/.local/lib
export PYTHONPATH=$(pwd)/src
40 changes: 40 additions & 0 deletions bin/coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash
#
# Note: cython's Cython/Coverage.py fails for pyx files that are included in
# other pyx files. This gives the following error:
#
# $ coverage report -m
# Plugin 'Cython.Coverage.Plugin' did not provide a file reporter for
# '.../python-flint/src/flint/fmpz.pyx'.
#
# A patch to the file is needed:
#
# --- Coverage.py.backup 2022-12-09 17:36:35.387690467 +0000
# +++ Coverage.py 2022-12-09 17:08:06.282516837 +0000
# @@ -172,7 +172,9 @@ class Plugin(CoveragePlugin):
# else:
# c_file, _ = self._find_source_files(filename)
# if not c_file:
# - return None
# + c_file = os.path.join(os.path.dirname(filename), 'pyflint.c')
# + if not os.path.exists(c_file):
# + return None
# rel_file_path, code = self._read_source_lines(c_file, filename)
# if code is None:
# return None # no source found
#
#

set -o errexit

source bin/activate

export PYTHON_FLINT_COVERAGE=true

python setup.py build_ext --inplace

coverage run test/test.py
coverage run --append test/dtest.py

coverage report -m
coverage html
20 changes: 18 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
from Cython.Build import cythonize
from numpy.distutils.system_info import default_include_dirs, default_lib_dirs

from distutils.sysconfig import get_config_vars


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


default_include_dirs += [
os.path.join(d, "flint") for d in default_include_dirs
]


define_macros = []
compiler_directives = {'language_level':2}


# Enable coverage tracing
if os.getenv('PYTHON_FLINT_COVERAGE'):
define_macros.append(('CYTHON_TRACE', 1))
compiler_directives['linetrace'] = True


ext_modules = [
Extension(
"flint._flint", ["src/flint/pyflint.pyx"],
libraries=libraries,
library_dirs=default_lib_dirs,
include_dirs=default_include_dirs)
include_dirs=default_include_dirs,
define_macros=define_macros,
)
]

for e in ext_modules:
Expand All @@ -54,7 +70,7 @@
setup(
name='python-flint',
cmdclass={'build_ext': build_ext},
ext_modules=ext_modules,
ext_modules=cythonize(ext_modules, compiler_directives=compiler_directives),
packages=['flint'],
package_dir={'': 'src'},
description='Bindings for FLINT and Arb',
Expand Down