Skip to content

Commit 792ef62

Browse files
committed
👌 Template: improve Hatch environments
Make several improvements to the template Hatch environments: - Use `uv` as the installer for each environment by setting it in the `default` one. - Instead of having a custom `tests` environment, use the built-in `hatch-test` one. Moreover, set up a test matrix for all supported Python versions. This allows template users to run the test suite with `hatch test`, and easily select a Python version with `-py` or run all supported versions with `--all`. We explicitly configure the environment to simply run `pytest` without any additional default arguments, and without parallelization or randomization to make `hatch test` correspond to a regular `pytest` run. - Rename the `precommit` environment to `pre-commit`. The package and command are hyphenated, and so it's better to also do this for the environment for consistency. The Hatch `check` script of the template package is updated to reflect the last change, and we also add a `test` script that copies the template and runs its tests.
1 parent 8b84823 commit 792ef62

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

‎docs/developer.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Other scripts for the default environment:
2727
* `check`: Copy/Update the template in the `.tmp` directory and check the rendered files by linting them with `hatch fmt -l`.
2828
* `clean`: Remove the `.tmp` directory and any Ruff caches.
2929
* `install`: Copy/Update the template in the `.tmp` directory and install it with `uv pip install`.
30+
* `test`: Copy/Update the template in the `.tmp` directory run the test suite with `pytest`.
3031

3132
## Documentation
3233

‎pyproject.toml‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ scripts.install = [
1313
]
1414
scripts.check = [
1515
"copier copy --vcs-ref=HEAD . .tmp/py-package -f",
16-
"cd .tmp/py-package && hatch run precommit:run -av",
16+
"cd .tmp/py-package && hatch run pre-commit:run -av",
17+
]
18+
scripts.test = [
19+
"copier copy --vcs-ref=HEAD . .tmp/py-package -f",
20+
"cd .tmp/py-package && hatch test -v -- -s",
1721
]
1822
scripts.clean = [
1923
"ruff clean",

‎template/pyproject.toml.jinja‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ classifiers = [
2424
[tool.hatch.version]
2525
path = "src/{{ package_name.lower().replace('-', '_') }}/__about__.py"
2626

27+
[tool.hatch.envs.default]
28+
installer = 'uv'
29+
2730
{% if docs == 'myst'-%}
2831
[tool.hatch.envs.docs]
2932
dependencies = [
@@ -44,14 +47,19 @@ scripts.serve = "mkdocs serve --dev-addr localhost:8000"
4447
scripts.deploy = "mkdocs gh-deploy --force"
4548
{%- endif %}
4649

47-
[tool.hatch.envs.precommit]
50+
[tool.hatch.envs.pre-commit]
4851
dependencies = ["pre-commit"]
4952
scripts.install = "pre-commit install"
50-
scripts.run = "pre-commit run {args:--all-files}"
53+
scripts.run = "pre-commit run {args}"
5154

52-
[tool.hatch.envs.tests]
55+
[tool.hatch.envs.hatch-test]
5356
dependencies = ["pytest"]
54-
scripts.run = "pytest {args}"
57+
randomize = false
58+
parallel = false
59+
run = "pytest {args}"
60+
61+
[[tool.hatch.envs.hatch-test.matrix]]
62+
python = ["3.9", "3.10", "3.11", "3.12", "3.13"]
5563

5664
[tool.ruff]
5765
lint.ignore = [

0 commit comments

Comments
 (0)