Generating coverage report for Cython files using a meson-python build backend

24 views
Skip to first unread message

Joseph Capriotti

unread,
May 25, 2024, 3:20:56 PMMay 25
to cython-users
I've been trying, and struggling to generate accurate coverage reports for our project's Cython files. It only seems to generate coverage reports for the lines that have interaction with python code. (not any lines which are translated to pure C). I do not know what else is happening or where this process is wrong.

The project uses meson-python as the build backend. One of the intended designs of the meson system is that it doesn't put built files in the source directories (meaning the transpiled C/C++ codes end up in a build directory). meson-python supports extension modules with in place building by installing hooks to the compiled codes that live in the build directory, (but by default these do not exist next to the transpiled code either). From what I understand the Cython.Coverage tool looks for the transpiled codes to live next to their source pyx files, therefore I've added a step that cythonizes (with '--directive linetrace=true') those sources again so that transpiled code ends up next to the pyx source. This process seems to allow coverage.py tool to find the correct c/cpp file.

During a coverage build, I tell meson to add the `--directive linetrace=true` directive to the cython project arguments, and `-DCYTHON_TRACE_NOGIL=1` to both the C and C++ project arguments. The commands that the ninja build executes "look" correct, for example. I've tried both `debug` and `release` meson builds, and neither makes a difference in the coverage.

For reference here are my attempts at getting it working:  https://github.com/simpeg/discretize/pull/357


And the coverage reported for the cython extensions.

As you can see it completely misses coverage of `simplex_helpers.pyx`, and the other files only report coverage on lines that had any (even the smallest) interaction with python.

Oscar Benjamin

unread,
May 29, 2024, 6:15:59 AMMay 29
to cython...@googlegroups.com
On Sat, 25 May 2024 at 20:20, Joseph Capriotti
<josephrc...@gmail.com> wrote:
>
> I've been trying, and struggling to generate accurate coverage reports for our project's Cython files. It only seems to generate coverage reports for the lines that have interaction with python code. (not any lines which are translated to pure C). I do not know what else is happening or where this process is wrong.
>
> The project uses meson-python as the build backend.

See https://github.com/cython/cython/issues/6186

One problem is that in an out of tree build with src layout Cython
only outputs the basename of the files.

--
Oscar
Reply all
Reply to author
Forward
0 new messages