Skip to content
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

🧪 Collect Cython coverage in CI #961

Merged
merged 2 commits into from
Nov 23, 2023
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
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
Loading