From a4d84fd76d4c80266e2fd6c9ec9208403053caed Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Sat, 2 Nov 2024 15:22:06 +0100 Subject: [PATCH 1/3] Implement dependency groups --- {{cookiecutter.package_name}}/pyproject.toml | 45 ++++++++++- {{cookiecutter.package_name}}/tox.ini | 84 +++++++++----------- 2 files changed, 81 insertions(+), 48 deletions(-) diff --git a/{{cookiecutter.package_name}}/pyproject.toml b/{{cookiecutter.package_name}}/pyproject.toml index ca1db0c..2a70a7a 100644 --- a/{{cookiecutter.package_name}}/pyproject.toml +++ b/{{cookiecutter.package_name}}/pyproject.toml @@ -58,7 +58,8 @@ dependencies = [ {% endif %} ] -[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", @@ -74,6 +75,48 @@ docs = [ # If you uncomment this, don't forget to do the same in docs/conf.py # texext ] +lint = [ + "ruff", +] +typing = [ + "mypy", + "pydantic", +] +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/#dependencies-optional-dependencies +# [project.optional-dependencies] + # 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} From c60fe1dc7d4a8447dd8436214aa0f8f3c999c491 Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Sat, 2 Nov 2024 15:23:58 +0100 Subject: [PATCH 2/3] Update .readthedocs.yml --- {{cookiecutter.package_name}}/.readthedocs.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/{{cookiecutter.package_name}}/.readthedocs.yml b/{{cookiecutter.package_name}}/.readthedocs.yml index 5212949..9cc42a6 100644 --- a/{{cookiecutter.package_name}}/.readthedocs.yml +++ b/{{cookiecutter.package_name}}/.readthedocs.yml @@ -16,5 +16,6 @@ python: install: - method: pip path: . + # TODO resolve issue where docs should be a dependency group now extra_requirements: - docs From 63892ab050da2d4f58de51f6a1a2a08fb2f16ec6 Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Thu, 14 Nov 2024 13:56:03 +0100 Subject: [PATCH 3/3] Update .readthedocs.yml --- {{cookiecutter.package_name}}/.readthedocs.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/{{cookiecutter.package_name}}/.readthedocs.yml b/{{cookiecutter.package_name}}/.readthedocs.yml index 9cc42a6..8edfaee 100644 --- a/{{cookiecutter.package_name}}/.readthedocs.yml +++ b/{{cookiecutter.package_name}}/.readthedocs.yml @@ -14,8 +14,6 @@ build: python: install: - - method: pip - path: . - # TODO resolve issue where docs should be a dependency group now - extra_requirements: - - docs + # partial override of build commands was added in https://github.com/readthedocs/readthedocs.org/pull/11710 + # you can include extras with .[] notation + - pip install --dependency-groups=docs .