From b7837afe6d3b2f93d8cc9c5c8edfcceba5de8b6e Mon Sep 17 00:00:00 2001 From: "Patrick J. Roddy" Date: Wed, 23 Jul 2025 16:18:29 +0100 Subject: [PATCH 1/5] Switch to `dependency-groups` --- README.md | 2 +- .../test_package_generation/pyproject.toml | 42 ++++++++++--------- tutorial.md | 4 +- {{cookiecutter.project_slug}}/pyproject.toml | 42 ++++++++++--------- 4 files changed, 49 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index a117a315..72e20ebf 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ cd example-research-software-project git init # uv venv # source .venv/bin/activate -uv pip install -e ".[dev]" +uv pip install -e . --group dev ``` diff --git a/tests/data/test_package_generation/pyproject.toml b/tests/data/test_package_generation/pyproject.toml index 6a488554..bb190c47 100644 --- a/tests/data/test_package_generation/pyproject.toml +++ b/tests/data/test_package_generation/pyproject.toml @@ -5,6 +5,27 @@ requires = [ "setuptools-scm", ] +[dependency-groups] +dev = [ + "build", + "mypy", + "pre-commit", + "ruff", + "tox", + "twine", +] +docs = [ + "mkdocs", + "mkdocs-include-markdown-plugin", + "mkdocs-material", + "mkdocstrings", + "mkdocstrings-python", +] +test = [ + "pytest", + "pytest-cov", +] + [project] authors = [ {email = "eva.lu.ator@ucl.ac.uk", name = "Eva Lu Ator"}, @@ -31,23 +52,6 @@ license-files = [ "LICENSE.md", ] name = "cookiecutter-test" -optional-dependencies = {dev = [ - "build", - "mypy", - "pre-commit", - "ruff", - "tox", - "twine", -], docs = [ - "mkdocs", - "mkdocs-include-markdown-plugin", - "mkdocs-material", - "mkdocstrings", - "mkdocstrings-python", -], test = [ - "pytest", - "pytest-cov", -]} readme = "README.md" requires-python = ">=3.11" urls.homepage = "https://github.com/test-user/cookiecutter-test" @@ -126,7 +130,7 @@ env_run_base = {commands = [ "--cov", "--cov-report=xml", ], -], extras = [ +], dependency_groups = [ "test", ]} env.docs = {commands = [ @@ -135,7 +139,7 @@ env.docs = {commands = [ "build", "--strict", ], -], extras = [ +], dependency_groups = [ "docs", ]} gh.python."3.11" = ["py311"] diff --git a/tutorial.md b/tutorial.md index f4c2ee78..dc64727c 100644 --- a/tutorial.md +++ b/tutorial.md @@ -309,7 +309,7 @@ uv venv --python 3.11.6 Once you have created and activated a virtual environment for the project, you can install the package in [editable mode](https://setuptools.pypa.io/en/latest/userguide/development_mode.html), along with both its required dependencies and optional sets of dependencies for development (`dev`), documentation (`docs`) and testing (`test`) by running ```sh -uv pip install --editable ".[dev,docs,test]" +uv pip install --editable . --group dev --group docs --group test ``` from the root of the project repository. @@ -343,7 +343,7 @@ python -m pip install --upgrade pip Similar to `uv`, once the environment is active, you can install the package in editable mode as well as all dependencies: ```sh -python -m pip install --editable ".[dev,docs,test]" +python -m pip install --editable . --group dev --group docs --group test ``` diff --git a/{{cookiecutter.project_slug}}/pyproject.toml b/{{cookiecutter.project_slug}}/pyproject.toml index 64cacb44..ff1c0861 100644 --- a/{{cookiecutter.project_slug}}/pyproject.toml +++ b/{{cookiecutter.project_slug}}/pyproject.toml @@ -5,6 +5,27 @@ requires = [ "setuptools-scm", ] +[dependency-groups] +dev = [ + "build", + "mypy", + "pre-commit", + "ruff", + "tox", + "twine", +] +docs = [ + "mkdocs", + "mkdocs-include-markdown-plugin", + "mkdocs-material", + "mkdocstrings", + "mkdocstrings-python", +] +test = [ + "pytest", + "pytest-cov", +] + [project] authors = [ {email = "{{cookiecutter.author_email}}", name = "{{cookiecutter.author_given_names}} {{cookiecutter.author_family_names}}"}, @@ -34,23 +55,6 @@ license-files = [ "LICENSE.md", ] name = "{{cookiecutter.project_slug}}" -optional-dependencies = {dev = [ - "build", - "mypy", - "pre-commit", - "ruff", - "tox", - "twine", -], docs = [ - "mkdocs", - "mkdocs-include-markdown-plugin", - "mkdocs-material", - "mkdocstrings", - "mkdocstrings-python", -], test = [ - "pytest", - "pytest-cov", -]} readme = "README.md" requires-python = ">={{cookiecutter.min_python_version}}" urls.homepage = "{{cookiecutter.__repo_url}}" @@ -132,7 +136,7 @@ env_run_base = {commands = [ "--cov", "--cov-report=xml", ], -], extras = [ +], dependency_groups = [ "test", ]} env.docs = {commands = [ @@ -141,7 +145,7 @@ env.docs = {commands = [ "build", "--strict", ], -], extras = [ +], dependency_groups = [ "docs", ]} {%- for python_version in range( From 7edd06e94b9ae2759440b5fd3097c4baa3e0a0e5 Mon Sep 17 00:00:00 2001 From: "Patrick J. Roddy" Date: Thu, 24 Jul 2025 12:05:57 +0100 Subject: [PATCH 2/5] Add note on `uv` version --- README.md | 2 ++ tutorial.md | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 72e20ebf..a96e9ef7 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,8 @@ git init uv pip install -e . --group dev ``` +Note that `uv>=0.6.7` is required to use the `--group` option. + diff --git a/tutorial.md b/tutorial.md index dc64727c..13f76ffd 100644 --- a/tutorial.md +++ b/tutorial.md @@ -312,7 +312,7 @@ Once you have created and activated a virtual environment for the project, you c uv pip install --editable . --group dev --group docs --group test ``` -from the root of the project repository. +from the root of the project repository. Note that `uv>=0.6.7` is required to use the `--group` option.
Using venv as an alternative to uv From dfac016e2981a9d2b9e43221f06142ce3751f7fa Mon Sep 17 00:00:00 2001 From: "Patrick J. Roddy" Date: Thu, 24 Jul 2025 15:11:05 +0100 Subject: [PATCH 3/5] Switch to `uv sync` Co-authored-by: Paul Smith --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a96e9ef7..36521a78 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ cd example-research-software-project git init # uv venv # source .venv/bin/activate -uv pip install -e . --group dev +uv sync ``` Note that `uv>=0.6.7` is required to use the `--group` option. From e01c7c94083ebfc0df2108ba36e85d7db7eee66e Mon Sep 17 00:00:00 2001 From: "Patrick J. Roddy" Date: Thu, 24 Jul 2025 15:11:37 +0100 Subject: [PATCH 4/5] Sync all groups with `uv` Co-authored-by: Paul Smith --- tutorial.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorial.md b/tutorial.md index 13f76ffd..426c7e91 100644 --- a/tutorial.md +++ b/tutorial.md @@ -309,7 +309,7 @@ uv venv --python 3.11.6 Once you have created and activated a virtual environment for the project, you can install the package in [editable mode](https://setuptools.pypa.io/en/latest/userguide/development_mode.html), along with both its required dependencies and optional sets of dependencies for development (`dev`), documentation (`docs`) and testing (`test`) by running ```sh -uv pip install --editable . --group dev --group docs --group test +uv sync --all-groups ``` from the root of the project repository. Note that `uv>=0.6.7` is required to use the `--group` option. From b27751ca28dfbf547f408bd74163984aaa78cc07 Mon Sep 17 00:00:00 2001 From: "Patrick J. Roddy" Date: Thu, 24 Jul 2025 15:13:00 +0100 Subject: [PATCH 5/5] Add `pip` note --- tutorial.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tutorial.md b/tutorial.md index 426c7e91..9d8c1858 100644 --- a/tutorial.md +++ b/tutorial.md @@ -346,6 +346,8 @@ Similar to `uv`, once the environment is active, you can install the package in python -m pip install --editable . --group dev --group docs --group test ``` +Note that `pip>=25.1` is required to use the `--group` option. +
## 🧪 Running package tests locally