Skip to content

Commit aa121e5

Browse files
committed
Copier Template: Improve Git hook performance.
Also, * Copier Template: Refactor test commands to account for slow tests and doctests separately. * Copier Template: Return success from Pytest when no matching tests are found. (Useful for when there are no slow tests to run.) * Documentation: validation: Reflect test commands refactor. * Documentation: releases: Improve procedure for release candidates. * Copier Template: Claude Commands: release-final: Improve procedure for releases; bring it inline with manual releases procedure.
1 parent 2e447c0 commit aa121e5

8 files changed

Lines changed: 48 additions & 22 deletions

File tree

.auxiliary/configuration/pre-commit.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ repos:
4949
- repo: local
5050
hooks:
5151

52+
- id: hatch-pytest
53+
name: 'Test Code Units (Python)'
54+
fail_fast: true
55+
language: system
56+
always_run: true
57+
pass_filenames: false
58+
entry: 'hatch --env develop run pytest'
59+
5260
- id: hatch-pyright
5361
name: 'Lint: Pyright'
5462
stages: [ 'pre-push' ]

documentation/common/releases.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ Pre-Release Quality Check
3232
Run local quality assurance before any release process::
3333

3434
git status && git pull origin master
35-
hatch --env develop run linters
36-
hatch --env develop run testers
37-
hatch --env develop run docsgen
35+
hatch --env develop run make-all
3836

3937
Also, ensure that at least one news fragment exists under
4038
``.auxiliary/data/towncrier``.
@@ -70,8 +68,9 @@ Initial Release Candidate
7068

7169
git checkout master
7270
hatch version minor,alpha
73-
git commit -am "Start development for v$(hatch version | sed 's/a[0-9]*$//')."
74-
git tag -m "Start development for v$(hatch version | sed 's/a[0-9]*$//')." i$(hatch version | sed 's/a[0-9]*$//')
71+
next_release="$(hatch version | sed 's/a[0-9]*$//')"
72+
git commit -am "Start of development for release ${next_release}."
73+
git tag -m "Start of development for release ${next_release}." "i${next_release}"
7574
git push origin master --tags
7675

7776
Final Release

documentation/common/validation.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,13 @@ Run validation commands using ``hatch --env develop run <command>``.
3434
Runs code quality checks including Ruff linting, Pyright type checking, and
3535
Rust linting (if applicable). Must pass with no errors.
3636

37+
**pytest**
38+
Runs quick tests. Useful for quick validation during development.
39+
3740
**testers**
3841
Runs the full test suite with coverage reporting. Generates HTML and XML
3942
coverage reports in ``.auxiliary/artifacts/coverage-pytest/``.
4043

41-
**testers-no-reports**
42-
Runs tests without generating coverage reports. Useful for quick validation
43-
during development.
44-
4544
**packagers**
4645
Builds distribution packages using Hatch. Also builds standalone executables
4746
via PyInstaller (if enabled).
@@ -58,11 +57,11 @@ Run validation commands using ``hatch --env develop run <command>``.
5857
Workflow
5958
===============================================================================
6059

61-
1. **During Development**: Use ``testers-no-reports`` for quick feedback.
60+
1. **During Development**: Use ``pytest`` for quick feedback.
6261
2. **Before Committing**: Run ``linters`` to catch some bugs, code smells, and
6362
type issues.
6463
3. **Before Pull Requests**: Run ``make-all`` to ensure all validation passes.
6564

6665
All validation commands must pass without errors before contributions can be
6766
accepted. If you installed the Git pre-commit and pre-push hooks for the
68-
project, then they will perform these validations for you.
67+
project, then they will perform most of these validations for you.

template/.auxiliary/configuration/claude/commands/release-final.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ Set up next development version:
166166
```bash
167167
hatch version minor,alpha
168168
git commit -am "Start of development for release $(hatch version | sed 's/a[0-9]*$//')."
169-
git tag -m "Start of development for $(hatch version | sed 's/a[0-9]*$//')." "i$(hatch version | sed 's/a[0-9]*$//')"
169+
git tag -m "Start of development for release $(hatch version | sed 's/a[0-9]*$//')." "i$(hatch version | sed 's/a[0-9]*$//')"
170170
git push origin master --tags
171171
```
172172

template/.auxiliary/configuration/pre-commit.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ repos:
4949
- repo: local
5050
hooks:
5151

52+
- id: hatch-pytest
53+
name: 'Test Code Units (Python)'
54+
fail_fast: true
55+
language: system
56+
always_run: true
57+
pass_filenames: false
58+
entry: 'hatch --env develop run pytest'
59+
5260
- id: hatch-pyright
5361
name: 'Lint: Pyright'
5462
stages: [ 'pre-push' ]
@@ -83,4 +91,4 @@ repos:
8391
language: system
8492
always_run: true
8593
pass_filenames: false
86-
entry: 'hatch --env develop run packagers'
94+
entry: 'hatch build'

template/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ CONVENTIONS.md
99
GEMINI.md
1010
__pycache__/
1111
bugs/
12+
build/

template/pyproject.toml.jinja

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ gha-runners = [
7777
]
7878
[tool.coverage.run]
7979
branch = true
80-
command_line = '-m pytest' # TODO? '--fail-under'
80+
command_line = '-m pytest'
8181
data_file = '.auxiliary/caches/pytest/coverage.sqlite3'
8282
parallel = true
8383
source = [ 'sources' ]
@@ -165,9 +165,9 @@ HYPOTHESIS_STORAGE_DIRECTORY = '.auxiliary/caches/hypothesis'
165165
[tool.hatch.envs.develop.scripts]
166166
docsgen = [
167167
"""sphinx-build -E -b linkcheck -d .auxiliary/caches/sphinx \
168-
documentation .auxiliary/artifacts/sphinx-linkcheck""",
168+
documentation .auxiliary/artifacts/sphinx-linkcheck""",
169169
"""sphinx-build -a -d .auxiliary/caches/sphinx \
170-
documentation .auxiliary/artifacts/sphinx-html""",
170+
documentation .auxiliary/artifacts/sphinx-html""",
171171
]
172172
linters = [
173173
"""ruff check --quiet sources documentation tests""",
@@ -176,7 +176,7 @@ linters = [
176176
# TODO: Use '-C' flag, which is only on nightly, as of 2024-12-11.
177177
"""cargo check --manifest-path sources/{{ crate_name }}/Cargo.toml""",
178178
"""cargo clippy --manifest-path sources/{{ crate_name }}/Cargo.toml \
179-
-- --deny warnings --warn clippy::pedantic""",
179+
-- --deny warnings --warn clippy::pedantic""",
180180
# TODO: cargo deny # Not installed with Cargo by default.
181181
{%- endif %}
182182
# --- END: Injected by Copier ---
@@ -193,14 +193,19 @@ packagers = [
193193
{%- endif %}
194194
# --- END: Injected by Copier ---
195195
]
196+
testers-documentation = [
197+
"""coverage run -m sphinx.cmd.build \
198+
-E -b doctest -d .auxiliary/caches/sphinx \
199+
documentation .auxiliary/artifacts/sphinx-doctest""",
200+
]
201+
testers-serotine = [ """coverage run -m pytest -m 'slow'""" ]
196202
testers-no-reports = [
197-
'coverage erase',
198203
'coverage run',
199-
"""coverage run -m sphinx.cmd.build \
200-
-E -b doctest -d .auxiliary/caches/sphinx \
201-
documentation .auxiliary/artifacts/sphinx-doctest""",
204+
'testers-documentation',
205+
'testers-serotine',
202206
]
203207
testers = [
208+
'coverage erase',
204209
'testers-no-reports',
205210
'coverage combine',
206211
'coverage report --skip-covered',
@@ -287,11 +292,14 @@ stubPath = 'sources/{{ package_name }}/_typedecls'
287292
# Note: Cannot run doctests from Pytest, because Pytest tries to update '_'
288293
# attribute on protected modules. Instead, we use Sphinx to run doctests.
289294
minversion = '8.1'
290-
addopts = '--capture=no --exitfirst -rfE'
295+
addopts = """--capture=no --exitfirst -rfE -m 'not slow'""" # TODO? '--fail-under'
291296
testpaths = [ 'tests' ]
292297
python_files = [ 'test_*.py' ]
293298
python_functions = [ 'test_[0-9][0-9][0-9]_*' ]
294299
cache_dir = '.auxiliary/caches/pytest'
300+
markers = [
301+
"slow: long-running tests",
302+
]
295303

296304
[tool.ruff]
297305
#builtins = [ 'ic' ]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def pytest_sessionfinish( session, exitstatus ):
2+
if exitstatus == 5: # pytest exit code for "no tests collected"
3+
session.exitstatus = 0

0 commit comments

Comments
 (0)