Skip to content

ci: cache poetry venv keyed on lockfile and cython sources#1704

Merged
bdraco merged 2 commits into
masterfrom
ci/cache-poetry-venv
May 17, 2026
Merged

ci: cache poetry venv keyed on lockfile and cython sources#1704
bdraco merged 2 commits into
masterfrom
ci/cache-poetry-venv

Conversation

@bdraco
Copy link
Copy Markdown
Member

@bdraco bdraco commented May 17, 2026

Summary

Cache the poetry-managed .venv plus built Cython artefacts (src/zeroconf/**/*.so) across the test matrix and benchmark jobs. Mirrors dbus-fast#675 and the follow-up cleanup in dbus-fast#679, adapted to this repo's matrix shape.

Details

Cache key components:

  • runner.os + matrix.python-version + matrix.extension (skip_cython / use_cython)
  • hashFiles('poetry.lock', 'pyproject.toml', 'build_ext.py', 'src/zeroconf/**/*.py', 'src/zeroconf/**/*.pxd')

On a cache hit, the Install Dependencies step is skipped via if: steps.cache-venv.outputs.cache-hit != 'true'. Pure-Python and Cython-source changes both invalidate the cache, so we never run tests against stale .so files.

POETRY_VIRTUALENVS_IN_PROJECT: "true" is set at workflow-level env: so poetry creates .venv inside the repo (cacheable as a single path) and the env var lives in one place.

Why the cache key looks the way it does:

  • The extension axis is in the key because skip_cython and use_cython produce different venvs (one has .so files, one doesn't).
  • .c files are intentionally not cached. They're regenerated from .py/.pxd by Cython, and only needed when we rebuild — and on a hit we skip the rebuild.
  • pyproject.toml and build_ext.py are in the hash so changes to TO_CYTHONIZE, extension flags, or runtime deps invalidate the cache.

The matrix here is ~30 cells (7 Python × 3 OS × 2 extension modes, minus exclusions) plus the benchmark job, so unchanged-deps PRs that only touch tests or docs should now skip ~30 poetry installs and ~13 Cython rebuilds.

Test plan

  • First run on this branch is a cold cache (expected); subsequent runs that don't touch src/zeroconf/**/*.py or *.pxd should hit the cache and skip install
  • actions/cache step succeeds across Linux / macOS / Windows
  • use_cython cells continue to exercise the Cython extension (CodSpeed signal is the canary)
  • Free-threaded 3.14t entry still passes

bdraco added 2 commits May 17, 2026 13:20
Caches the poetry-managed .venv plus the built Cython artefacts
(src/zeroconf/**/*.so) for both the test matrix and benchmark
jobs, keyed on runner OS + image version + python version +
extension mode + hash of poetry.lock/pyproject.toml/build_ext.py
+ hash of src/zeroconf/**/*.py and **/*.pxd.

On a cache hit, the Install Dependencies step is skipped. Pure
Python and Cython source changes both invalidate the cache, so
tests never run against stale .so files.

POETRY_VIRTUALENVS_IN_PROJECT="true" is set at the job level so
poetry creates .venv inside the repo and the cache can target a
single path.
Three trims:

1. Drop ${{ env.ImageOS }}-${{ env.ImageVersion }}- from both
   cache keys. env context only resolves workflow-declared env
   vars, not runner process env vars like ImageOS / ImageVersion,
   so these interpolations were silently empty (visible in
   dbus-fast's post-merge logs of the same pattern).
2. Merge the two hashFiles() calls into one covering poetry.lock,
   pyproject.toml, build_ext.py, src/zeroconf/**/*.py, and
   src/zeroconf/**/*.pxd. Concatenated either way; one call is
   easier to read.
3. Promote POETRY_VIRTUALENVS_IN_PROJECT to workflow-level env:
   instead of duplicating on the test and benchmark jobs.
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 17, 2026

Merging this PR will not alter performance

✅ 6 untouched benchmarks


Comparing ci/cache-poetry-venv (80252ab) with master (d03ea36)

Open in CodSpeed

@codecov
Copy link
Copy Markdown

codecov Bot commented May 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.76%. Comparing base (d03ea36) to head (80252ab).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1704   +/-   ##
=======================================
  Coverage   99.76%   99.76%           
=======================================
  Files          33       33           
  Lines        3410     3410           
  Branches      464      464           
=======================================
  Hits         3402     3402           
  Misses          5        5           
  Partials        3        3           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bdraco bdraco merged commit cab5fa8 into master May 17, 2026
37 checks passed
@bdraco bdraco deleted the ci/cache-poetry-venv branch May 17, 2026 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant