Skip to content

Commit 018bb4d

Browse files
committed
Add new coverage component
1 parent 6d797ae commit 018bb4d

5 files changed

Lines changed: 50 additions & 7 deletions

File tree

changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
- **Breaking:** the Codecov integration is removed, along with the `codecov` component, its `.github/codecov.yaml`, and the `coverage_cells` metadata key. `repomatic init` prunes an untouched orphaned config; delete the `CODECOV_TOKEN` secret and coverage badge by hand.
99
- **Breaking:** attestation bundles now carry the full filename of the asset they attest, so `repomatic-manpages.attestation.json` becomes `repomatic-manpages.tar.gz.attestation.json`. A repository declaring one extra asset gets `<filename>.attestation.json` in place of `<package-name>-extra-assets.attestation.json`.
1010
- New `pack-attestation` command names an attestation bundle after the asset it attests and prints the release upload list.
11+
- New `coverage` component: `repomatic init coverage` writes a `[tool.coverage]` section carrying branch coverage, report precision and a `report.fail_under` ratchet, shipped disabled.
1112
- The test suite now fails below the `[tool.coverage] report.fail_under` coverage floor, set to `78` for this project.
13+
- The bundled pytest config drops `--cov-branch` and `--cov-precision` from `addopts`, now carried by the `coverage` component. Existing `[tool.pytest]` sections are left alone; run `repomatic init coverage` to pick the settings back up.
1214
- The release lane's `publish-release` job now checks out the repository, so uploading binaries to the release no longer fails with `Failed to spawn: repomatic`. `7.7.0` shipped with no standalone executables because of it.
1315
- `lint-changelog` re-confirms a release live before dropping its availability admonition, so a day-old cache no longer reports a just-published version as missing.
1416
- The readme's logo is now an absolute URL, so it renders on the PyPI project page instead of 404ing.

repomatic/data/coverage.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Coverage.py configuration for Python projects.
2+
#
3+
# Native format - the keys coverage.py reads. When merged into pyproject.toml
4+
# via `repomatic init coverage`, the [tool.coverage] prefix is added
5+
# automatically.
6+
#
7+
# Pairs with the pytest config (`repomatic init pytest`), which turns coverage
8+
# on and names what to measure. *What* is measured is a pytest flag; *how* it
9+
# is measured and reported belongs here.
10+
11+
# https://coverage.readthedocs.io/en/latest/config.html
12+
run.branch = true
13+
report.precision = 2
14+
# Coverage ratchet: the suite fails below this percentage, 0 disables it.
15+
# Raise it to a few points under the number your suite actually reaches: close
16+
# enough to catch a real regression, loose enough to absorb the spread across
17+
# an OS matrix.
18+
#
19+
# Set the floor here and nowhere else. A --cov-fail-under flag outranks this
20+
# value, so passing one from a CI workflow silently shadows whatever a project
21+
# configures. The two runs not meant to clear a full-suite floor opt out
22+
# explicitly instead: a partial CI slice with --cov-fail-under=0, and a focused
23+
# local run with --no-cov.
24+
report.fail_under = 0

repomatic/data/pytest.toml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@
1010
addopts = [
1111
# Show the N slowest tests.
1212
"--durations=10",
13-
# Coverage settings - customize the package name for your project. Set the
14-
# coverage floor in [tool.coverage] as report.fail_under, never here and
15-
# never from CI: a --cov-fail-under flag outranks that config and shadows
16-
# it. Runs not meant to clear it (a focused local run) pass --no-cov.
13+
# Turn coverage on and name what to measure: customize this to your own
14+
# package. Everything about *how* coverage is measured and reported (branch
15+
# coverage, precision, and the report.fail_under ratchet) lives in
16+
# [tool.coverage] instead, via `repomatic init coverage`.
1717
"--cov=.",
18-
"--cov-branch",
19-
"--cov-precision=2",
2018
"--cov-report=term",
2119
# Run tests in parallel across all logical cores. Requires the
2220
# pytest-xdist[psutil] test dependency.

repomatic/registry.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,15 @@ def _workflow_entry(
792792
insert_after=("tool.ruff", "tool.ruff.format"),
793793
insert_before=("tool.mypy",),
794794
),
795+
ToolConfigComponent(
796+
name="coverage",
797+
description="Coverage.py measurement and reporting configuration",
798+
init_default=InitDefault.EXPLICIT,
799+
source_file="coverage.toml",
800+
tool_section="tool.coverage",
801+
insert_after=("tool.pytest",),
802+
insert_before=("tool.mdformat", "tool.bumpversion"),
803+
),
795804
ToolConfigComponent(
796805
name="mypy",
797806
description="Mypy type checking configuration",

tests/test_init_project.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,13 +295,18 @@ def test_exportable_file_loadable(filename: str) -> None:
295295
# have extras.
296296
_TEMPLATE_EXCLUDE_KEYS: dict[str, frozenset[str]] = {
297297
"bumpversion": frozenset({"current_version"}),
298+
# The template ships the coverage ratchet disabled (`fail_under = 0`), so
299+
# adopting a repomatic release never fails a downstream build on a floor
300+
# its author never picked. This repository sets its own.
301+
"coverage": frozenset({"fail_under"}),
298302
"mypy": frozenset(),
299303
"pytest": frozenset({"addopts"}),
300304
"ruff": frozenset({"extend-include"}),
301305
"typos": frozenset(),
302306
}
303307
_TEMPLATE_SUPERSET_KEYS: dict[str, frozenset[str]] = {
304308
"bumpversion": frozenset({"files"}),
309+
"coverage": frozenset(),
305310
"mypy": frozenset(),
306311
"pytest": frozenset(),
307312
"ruff": frozenset(),
@@ -410,6 +415,12 @@ def _lookup(parsed: dict, key: str):
410415
# an installed copy of the package.
411416
("pytest.toml", "testpaths", ["tests"]),
412417
("pytest.toml", "xfail_strict", True),
418+
# Coverage measurement and reporting, moved out of the pytest addopts
419+
# so they sit where coverage.py itself reads them.
420+
("coverage.toml", "run.branch", True),
421+
("coverage.toml", "report.precision", 2),
422+
# The ratchet ships disabled: a downstream repo opts in by raising it.
423+
("coverage.toml", "report.fail_under", 0),
413424
),
414425
)
415426
def test_template_setting(template: str, key: str, expected) -> None:
@@ -423,7 +434,6 @@ def test_template_setting(template: str, key: str, expected) -> None:
423434
("ruff.toml", "lint.ignore", "D400"),
424435
("ruff.toml", "lint.ignore", "ERA001"),
425436
("pytest.toml", "addopts", "--durations=10"),
426-
("pytest.toml", "addopts", "--cov-branch"),
427437
("pytest.toml", "addopts", "--cov-report=term"),
428438
("pytest.toml", "addopts", "--numprocesses=auto"),
429439
("pytest.toml", "addopts", "--import-mode=importlib"),

0 commit comments

Comments
 (0)