Fix Cython coverage collection in CI#1808
Fix Cython coverage collection in CI#1808rodrigobnogueira wants to merge 2 commits intoaio-libs:masteraio-libs/yarl:masterfrom rodrigobnogueira:fix/translate-cython-linetracerodrigobnogueira/yarl:fix/translate-cython-linetraceCopy head branch name to clipboard
Conversation
The translate-cython step regenerates the C files that the Cython.Coverage plugin reads, but it stopped requesting the linetrace directive when line tracing became opt-in in aio-libs#1521, so the plugin saw untraceable modules and recorded no data for the Cython sources. Cython 3.1+ also routes tracing through sys.monitoring on CPython 3.12+, which never reaches the plugin; traced builds now define CYTHON_USE_SYS_MONITORING=0 to request the legacy tracing hooks.
1b5f065 to
f07229d
Compare
With the Cython modules back in the measured set, macOS test jobs bottom out around 98.4 percent because platform-specific tests are skipped there. The previous 98.95 floor was calibrated during the period when the *.pyx files were silently absent from measurement.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1808 +/- ##
==========================================
- Coverage 99.86% 99.54% -0.33%
==========================================
Files 22 23 +1
Lines 4570 4865 +295
Branches 258 258
==========================================
+ Hits 4564 4843 +279
- Misses 3 19 +16
Partials 3 3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Vizonex
left a comment
There was a problem hiding this comment.
As someone who enjoys the Cython language a bit more than maybe some other people. I have chosen to review this PR myself. I have added myself to the list of reviewers as a result and I believe adding coverage for Cython would be beneficial. While it is annoying to hit every nook and cranny for testing code I have no complaintss bout this. The comments clearly state what this change is doing for anybody that is confused about this.
What do these changes do?
Restore
*.pyxcoverage collection, which has been broken in two stacked layers.translate-cythonCLI, which CI runs to regenerate the C files that theCython.Coverageplugin reads, was building its cythonize arguments without requesting thelinetracedirective after Only enable line tracing when building with Cython tracing #1521 made tracing opt-in (while inconsistently still patching the tracing env two lines below). The regenerated C files carried no trace instrumentation, the plugin treated every Cython module as untraceable, and nothing was recorded. The good-to-bad window bisected in the issue contains exactly one commit, and it is Only enable line tracing when building with Cython tracing #1521.sys.monitoringon CPython 3.12+, and those events never reach the plugin, which only works with the coverage.py "ctrace" core that.coveragercalready pins. Traced builds now defineCYTHON_USE_SYS_MONITORING=0to request the legacy tracing hooks.Each fix is one line in the PEP 517 backend; both were confirmed independently with local A/B runs (details below). The per-job
fail_underfloor moves from 98.95 to 98: restoring the*.pyxstatements to the measured set puts macOS jobs at roughly 98.4 (platform-specific tests are skipped there), and the old floor had been calibrated while those statements were invisible.Are there changes in behavior for the user?
No. Both changes only affect builds that request Cython line tracing; release wheels are unchanged.
Is it a substantial burden for the maintainers to support this?
No, it is two lines in the existing tracing seam plus a comment.
Related issue number
Fixes #1581. The same two-layer diagnosis likely applies to ansible/pylibssh#781, which shares this backend.
Checklist
CONTRIBUTORS.txt(N/A: the repo has no such file)CHANGES/folderVerification details (for reviewers)
All runs on CPython 3.13, Cython 3.2.8 (the current pin), coverage 7.x, macOS arm64, with a wheel built with
with-cython-tracing=trueinstalled and.coveragercin effect.translate-cythonoutput:grep -c __Pyx_TraceLine yarl/_quoting_c.creturns 0. With fix 1: 367._quoting_c.pyxrow in the report; traced C file restores it. This reproduces the exact codecov symptom from the issue (file listed, no data).CYTHON_USE_SYS_MONITORINGleft at its default, no.pyxframes ever reach coverage under the ctrace core; with the define, data flows.translate-cython,python -Im pytest tests/test_quoting.py --cov-report=xml):yarl/_quoting_c.pyxpresent incoverage.xmlwith 276 of 292 statements hit._quoting_c.pyxat 94.52, which is what sets the new per-job floor; the first CI round confirmed the fix end-to-end (Linux and Windows green with.pyxmeasured, patch coverage 99.54) and failed only on the stale macOS floor.pre-commitpasses on the changed files.make doc-spellingcould not run on this machine (no libenchant available); the news fragment keeps all technical terms in RST literals and uses only wordlist-known words otherwise.