Skip to content

Commit

Permalink
🧪 Collect Cython coverage in CI (#961)
Browse files Browse the repository at this point in the history
  • Loading branch information
webknjaz committed Nov 23, 2023
1 parent 777acc9 commit 0211310
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ show_missing = true
[run]
branch = true
cover_pylib = false
plugins = Cython.Coverage
relative_files = true
source =
tests
Expand Down
37 changes: 37 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ jobs:
os: ${{ matrix.os }}
source-tarball-name: ${{ needs.pre-setup.outputs.sdist-name }}
dists-artifact-name: ${{ needs.pre-setup.outputs.dists-artifact-name }}
cython-tracing: >- # Cython line tracing for coverage collection
${{
(
github.event_name == 'push'
&& contains(github.ref, 'refs/tags/')
)
&& '0'
|| '1'
}}
test:
name: Test
Expand Down Expand Up @@ -202,6 +211,34 @@ jobs:
shell: bash
- name: Self-install
run: python -Im pip install '${{ steps.wheel-file.outputs.path }}'
- name: Produce the C-files for the Coverage.py Cython plugin
if: >- # Only works if the dists were built with line tracing
!matrix.no-extensions
&& (
github.event_name != 'push'
|| !contains(github.ref, 'refs/tags/')
)
run: >
set -eEuo pipefail
python -Im cython
-X linetrace=true
-X embedsignature=true
-X emit_code_comments=true
yarl/*.pyx
shell: bash
- name: Disable the Cython.Coverage Produce plugin
if: >- # Only works if the dists were built with line tracing
matrix.no-extensions
|| (
github.event_name == 'push'
&& contains(github.ref, 'refs/tags/')
)
run: |
set -eEuo pipefail
sed -i 's/^plugins = .*//g' .coveragerc
shell: bash
- name: Run unittests
env:
YARL_NO_EXTENSIONS: ${{ matrix.no-extensions }}
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/reusable-build-wheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ on:
description: Workflow artifact name containing dists
required: true
type: string
cython-tracing:
description: Whether to build Cython modules with line tracing
default: '0'
required: false
type: string
os:
description: VM OS to use, without version suffix
default: ubuntu
Expand Down Expand Up @@ -64,6 +69,9 @@ jobs:
uses: pypa/cibuildwheel@v2.16.2
env:
CIBW_ARCHS_MACOS: x86_64 arm64 universal2
CIBW_ENVIRONMENT: >- # Cython line tracing for coverage collection
PIP_CONSTRAINT="requirements/cython.txt"
YARL_CYTHON_TRACING="${{ inputs.cython-tracing }}"
- name: Upload built artifacts for testing and publishing
uses: actions/upload-artifact@v3
Expand Down
15 changes: 15 additions & 0 deletions CHANGES/961.contrib.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Coverage collection has been implemented for the Cython modules
-- by :user:`webknjaz`.

It will also be reported to Codecov from any non-release CI jobs.

To measure coverage in a development environment, *yarl* can be
installed in editable mode, which requires an environment variable
``YARL_CYTHON_TRACING=1`` to be set:

.. code-block:: console
$ YARL_CYTHON_TRACING=1 python -Im pip install -e .
Editable install produces C-files required for the Cython coverage
plugin to map the measurements back to the PYX-files.
2 changes: 2 additions & 0 deletions docs/spelling_wordlist.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
Bluesky
Bugfixes
Changelog
Codecov
Cython
GPG
IPv
PRs
PYX
Towncrier
Twitter
UTF
Expand Down
1 change: 1 addition & 0 deletions requirements/test.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-r cython.txt
idna==3.4
multidict==6.0.4
pytest==7.4.3
Expand Down

0 comments on commit 0211310

Please sign in to comment.