Skip to content

Commit

Permalink
Implement dependency groups (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
cthoyt authored Nov 2, 2024
1 parent 3089b54 commit 69d67c9
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 48 deletions.
44 changes: 43 additions & 1 deletion {{cookiecutter.package_name}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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]
Expand Down
84 changes: 37 additions & 47 deletions {{cookiecutter.package_name}}/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand All @@ -65,64 +64,58 @@ 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 .
description = Run the pyroma tool to check the package friendliness of the project.

[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.
Expand All @@ -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 =
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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/*
Expand All @@ -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}
Expand Down Expand Up @@ -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/*
Expand All @@ -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}
Expand Down

0 comments on commit 69d67c9

Please sign in to comment.