From 69d67c94908450e4e46b125bd6c9ee11a3b6f27c Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Sat, 2 Nov 2024 15:03:42 +0100 Subject: [PATCH] Implement dependency groups (#27) --- {{cookiecutter.package_name}}/pyproject.toml | 44 +++++++++- {{cookiecutter.package_name}}/tox.ini | 84 +++++++++----------- 2 files changed, 80 insertions(+), 48 deletions(-) diff --git a/{{cookiecutter.package_name}}/pyproject.toml b/{{cookiecutter.package_name}}/pyproject.toml index ca1db0c..5517c07 100644 --- a/{{cookiecutter.package_name}}/pyproject.toml +++ b/{{cookiecutter.package_name}}/pyproject.toml @@ -58,11 +58,22 @@ dependencies = [ {% endif %} ] -[project.optional-dependencies] +# see https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#dependencies-optional-dependencies +# [project.optional-dependencies] + +# see https://peps.python.org/pep-0735/ and https://docs.astral.sh/uv/concepts/dependencies/#dependency-groups +[dependency-groups] tests = [ "pytest", "coverage", ] +lint = [ + "ruff", +] +typing = [ + "mypy", + "pydantic", +] docs = [ "sphinx>=8", "sphinx-rtd-theme>=3.0", @@ -74,6 +85,37 @@ docs = [ # If you uncomment this, don't forget to do the same in docs/conf.py # texext ] +doc8 = [ + {include-group = "docs"}, + "doc8", +] +rstfmt = [ + {include-group = "docs"}, + "rstfmt", +] +doctests = [ + "xdoctest", + "pygments", +] +pyroma = [ + "pyroma", + "pygments", +] +bump = [ + "bump-my-version", +] +build = [ + "uv", + "setuptools", +] +release = [ + {include-group = "build"}, + "twine", +] +manifest = [ + "check-manifest", +] + # See https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#urls [project.urls] diff --git a/{{cookiecutter.package_name}}/tox.ini b/{{cookiecutter.package_name}}/tox.ini index 59a77fd..479f147 100644 --- a/{{cookiecutter.package_name}}/tox.ini +++ b/{{cookiecutter.package_name}}/tox.ini @@ -38,8 +38,8 @@ commands = coverage run -p -m pytest --durations=20 {posargs:tests} coverage combine coverage xml -extras = - # See the [project.optional-dependencies] entry in pyproject.toml for "tests" +# See the [dependency-groups] entry in pyproject.toml for "tests" +dependency-groups = tests [testenv:coverage-clean] @@ -52,9 +52,8 @@ commands = coverage erase description = Test that documentation examples run properly. commands = xdoctest -m src -deps = - xdoctest - pygments +dependency-groups = + doctests [testenv:treon] description = Test that notebooks can run to completion @@ -65,45 +64,42 @@ deps = [testenv:format] description = Format the code in a deterministic way using ruff. Note that ruff check should come before ruff format when using --fix (ref: https://github.com/astral-sh/ruff-pre-commit/blob/main/README.md) -deps = - ruff +dependency-groups = + lint skip_install = true commands = ruff check --fix ruff format [testenv:format-docs] -description = Run documentation linters. # note that this doesn't work with sphinx-click # or any other extension that adds extra directives -deps = +description = Run documentation linters. +# See the [dependency-groups] entry in pyproject.toml for "rstfmt" +dependency-groups = rstfmt -extras = - # See the [project.optional-dependencies] entry in pyproject.toml for "docs" - docs skip_install = true commands = rstfmt docs/source/ [testenv:manifest] -deps = check-manifest +dependency-groups = + manifest skip_install = true commands = check-manifest description = Check that the MANIFEST.in is written properly and give feedback on how to fix it. [testenv:lint] description = Check code quality using ruff and other tools. - skip_install = true -deps = - ruff +dependency-groups = + lint commands = ruff check ruff format --check [testenv:pyroma] -deps = - pygments +dependency-groups = pyroma skip_install = true commands = pyroma --min=10 . @@ -111,18 +107,15 @@ description = Run the pyroma tool to check the package friendliness of the proje [testenv:mypy] description = Run the mypy tool to check static typing on the project. -deps = - mypy - pydantic +dependency-groups = + typing skip_install = true commands = mypy --install-types --non-interactive --ignore-missing-imports --strict src/ [testenv:doc8] skip_install = true -deps = +dependency-groups = doc8 -extras = - docs commands = doc8 docs/source/ description = Run the doc8 tool to check the style of the RST files in the project docs. @@ -137,8 +130,8 @@ commands = [testenv:docs] description = Build the documentation locally, allowing warnings. -extras = - # See the [project.optional-dependencies] entry in pyproject.toml for "docs" +dependency-groups = + # See the [dependency-groups] entry in pyproject.toml for "docs" docs # You might need to add additional extras if your documentation covers it commands = @@ -147,8 +140,8 @@ commands = [testenv:docs-test] description = Test building the documentation in an isolated environment. Warnings are considered as errors via -W. changedir = docs -extras = - {[testenv:docs]extras} +dependency-groups = + {[testenv:docs]dependency-groups} commands = mkdir -p {envtmpdir} cp -r source {envtmpdir}/source @@ -178,22 +171,21 @@ description = Bump the version number commands = bump-my-version bump {posargs} skip_install = true passenv = HOME -deps = - bump-my-version +dependency-groups = + bump [testenv:bumpversion-release] description = Remove the -dev tag from the version commands = bump-my-version bump release --tag skip_install = true passenv = HOME -deps = - bump-my-version +dependency-groups = + bump [testenv:build] skip_install = true -deps = - uv - setuptools +dependency-groups = + build commands = uv build --sdist --wheel --no-build-isolation @@ -230,9 +222,8 @@ skip_install = true passenv = TWINE_USERNAME TWINE_PASSWORD -deps = - {[testenv:build]deps} - twine >= 1.5.0 +dependency-groups = + release commands = {[testenv:build]commands} twine check dist/* @@ -247,9 +238,9 @@ passenv = HOME TWINE_USERNAME TWINE_PASSWORD -deps = - {[testenv:release]deps} - bump-my-version +dependency-groups = + bump + release commands = {[testenv:bumpversion-release]commands} {[testenv:release]commands} @@ -293,9 +284,8 @@ skip_install = true passenv = TWINE_USERNAME TWINE_PASSWORD -deps = - {[testenv:build]deps} - twine >= 1.5.0 +dependency-groups = + release commands = {[testenv:build]commands} twine check dist/* @@ -310,9 +300,9 @@ passenv = HOME TWINE_USERNAME TWINE_PASSWORD -deps = - {[testenv:testrelease]deps} - bump-my-version +dependency-groups = + bump + release commands = {[testenv:bumpversion-release]commands} {[testenv:testrelease]commands}