diff --git a/setup.py b/setup.py index 15769fc..46553da 100644 --- a/setup.py +++ b/setup.py @@ -5,6 +5,7 @@ import io import os +import platform import re from glob import glob from os.path import basename @@ -27,6 +28,17 @@ def read(*names, **kwargs): return fh.read() +# Enable code coverage for C code: we can't use CFLAGS=-coverage in tox.ini, since that may mess with compiling +# dependencies (e.g. numpy). Therefore we set SETUPPY_CFLAGS=-coverage in tox.ini and copy it to CFLAGS here (after +# deps have been safely installed). +if 'TOXENV' in os.environ and os.environ.get('SETUPPY_GCOV') == 'enabled' and platform.system() == 'Linux': + CFLAGS = ['-fprofile-arcs', '-ftest-coverage'] + LFLAGS = ['-lgcov'] +else: + CFLAGS = [] + LFLAGS = [] + + class optional_build_ext(build_ext): """Allow the building of C extensions to fail.""" def run(self): @@ -117,9 +129,9 @@ def _unavailable(self, e): Extension( splitext(relpath(path, 'src').replace(os.sep, '.'))[0], sources=[path], - extra_compile_args=os.environ.get('SETUPPY_CFLAGS', '').split(), - extra_link_args=os.environ.get('SETUPPY_LFLAGS', '').split(), - include_dirs=[dirname(path)], + extra_compile_args=CFLAGS, + extra_link_args=LFLAGS, + include_dirs=[dirname(path)] ) for root, _, _ in os.walk('src') for path in glob(join(root, '*.c')) diff --git a/tox.ini b/tox.ini index 90648da..c58cfe0 100644 --- a/tox.ini +++ b/tox.ini @@ -23,8 +23,7 @@ basepython = setenv = PYTHONPATH={toxinidir}/tests PYTHONUNBUFFERED=yes - cover: SETUPPY_CFLAGS=-fprofile-arcs -ftest-coverage - cover: SETUPPY_LFLAGS=-lgcov + cover: SETUPPY_GCOV=enabled passenv = * usedevelop =