Skip to content

Commit d6336db

Browse files
authored
Merge branch 'main' into sc/tox-warnings-on-freshly-cut-cookie
2 parents b59f50c + 58c1968 commit d6336db

File tree

7 files changed

+111
-109
lines changed

7 files changed

+111
-109
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ cd example-research-software-project
5555
git init
5656
# uv venv
5757
# source .venv/bin/activate
58-
uv pip install -e ".[dev]"
58+
uv sync
5959
```
6060

61+
Note that `uv>=0.6.7` is required to use the `--group` option.
62+
6163
<!-- links here -->
6264

6365
<!-- prettier-ignore-start -->

hooks/post_gen_project.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,12 @@ def main(initialise_git_repository: str, deploy_docs_to_github_pages: str) -> in
8686
return _EXIT_FAILURE
8787
if deploy_docs_to_github_pages == "True":
8888
print(
89-
"The 'Documentation' GitHub Actions workflow has been set up to push the "
90-
"built HTML documentation to a branch gh-pages on pushes to main for "
91-
"deploying as a GitHub Pages website. To allow the GitHub Actions bot to "
92-
"push to the gh-pages branch you need to enable 'Read and write "
93-
"permissions' under 'Workflow permissions' at\n\n"
94-
"{{cookiecutter.__repo_url}}/settings/actions\n\n"
95-
"After the 'Documentation' workflow has successfully completed at least "
96-
"once you will also need to configure the repository to deploy a GitHub "
97-
"pages site from the content on the gh-pages branch by going to\n\n"
89+
"The 'Documentation' GitHub Actions workflow has been set up to deploy the "
90+
"built HTML documentation to a GitHub Pages website on pushes to main. \n\n"
91+
"You will need to configure the repository to deploy a GitHub pages site "
92+
"using GitHub Actions by going to\n\n"
9893
"{{cookiecutter.__repo_url}}/settings/pages\n\n"
99-
"and under 'Built and deployment' selecting 'Deploy from a branch' for "
100-
"the 'Source' drop-down and 'gh-pages' for the 'Branch' drop-down, "
101-
"leaving the branch path drop-down with its default value of '/ (root)'.",
94+
"and under 'Build and deployment' selecting 'GitHub Actions' for 'Source'.",
10295
)
10396

10497
return _EXIT_SUCCESS

tests/data/test_package_generation/.github/workflows/docs.yml

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
pull_request:
88

99
jobs:
10-
docs:
10+
build:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- name: Checkout source
@@ -28,19 +28,26 @@ jobs:
2828

2929
- name: Install tox
3030
run: python -m pip install tox
31+
3132
- name: Build HTML documentation with tox
3233
run: tox -e docs
3334

34-
# Automatically deploy documentation to a GitHub Pages website on pushing to main.
35-
# Requires configuring the repository to deploy GitHub pages from a branch
36-
# gh-pages (https://tinyurl.com/gh-pages-from-branch), which will be created the
37-
# first time this workflow step is run.
38-
- name: Publish documentation on GitHub pages
39-
if: success() && github.event_name != 'pull_request'
40-
uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4
35+
- name: Upload built docs as artifact
36+
id: deployment
37+
uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa # v3
4138
with:
42-
github_token: ${{ secrets.GITHUB_TOKEN }}
43-
publish_dir: site
44-
publish_branch: gh-pages
45-
user_name: "github-actions[bot]"
46-
user_email: "github-actions[bot]@users.noreply.github.com"
39+
path: site
40+
41+
deploy:
42+
environment:
43+
name: github-pages
44+
url: ${{ steps.deployment.outputs.page_url }}
45+
permissions:
46+
pages: write
47+
id-token: write
48+
runs-on: ubuntu-latest
49+
needs: build
50+
steps:
51+
- name: Deploy to GitHub Pages
52+
id: deployment
53+
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4

tests/data/test_package_generation/pyproject.toml

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,27 @@ requires = [
55
"setuptools-scm",
66
]
77

8+
[dependency-groups]
9+
dev = [
10+
"build",
11+
"mypy",
12+
"pre-commit",
13+
"ruff",
14+
"tox",
15+
"twine",
16+
]
17+
docs = [
18+
"mkdocs",
19+
"mkdocs-include-markdown-plugin",
20+
"mkdocs-material",
21+
"mkdocstrings",
22+
"mkdocstrings-python",
23+
]
24+
test = [
25+
"pytest",
26+
"pytest-cov",
27+
]
28+
829
[project]
930
authors = [
1031
{email = "eva.lu.ator@ucl.ac.uk", name = "Eva Lu Ator"},
@@ -31,23 +52,6 @@ license-files = [
3152
"LICENSE.md",
3253
]
3354
name = "cookiecutter-test"
34-
optional-dependencies = {dev = [
35-
"build",
36-
"mypy",
37-
"pre-commit",
38-
"ruff",
39-
"tox",
40-
"twine",
41-
], docs = [
42-
"mkdocs",
43-
"mkdocs-include-markdown-plugin",
44-
"mkdocs-material",
45-
"mkdocstrings",
46-
"mkdocstrings-python",
47-
], test = [
48-
"pytest",
49-
"pytest-cov",
50-
]}
5155
readme = "README.md"
5256
requires-python = ">=3.11"
5357
urls.homepage = "https://github.com/test-user/cookiecutter-test"
@@ -126,7 +130,7 @@ env_run_base = {commands = [
126130
"--cov",
127131
"--cov-report=xml",
128132
],
129-
], extras = [
133+
], dependency_groups = [
130134
"test",
131135
]}
132136
env.docs = {commands = [
@@ -135,7 +139,7 @@ env.docs = {commands = [
135139
"build",
136140
"--strict",
137141
],
138-
], extras = [
142+
], dependency_groups = [
139143
"docs",
140144
]}
141145
gh.python."3.11" = ["py311"]

tutorial.md

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -189,60 +189,44 @@ When you pushed to `main` you will have triggered runs of the [GitHub actions](h
189189
You can view the status of the workflow jobs by browsing the `Actions` button at the top bar of the repository homepage, which takes you to `https://github.com/{github_owner}/{project_slug}/actions`.
190190

191191
Depending on your account settings, you may find that the `Documentation` workflow shows as failed (❌).
192-
If you see this it's probably because of the repository permissions settings for GitHub Actions.
192+
If you see this it's probably because of the repository setting specifying the source for deploying a GitHub pages site from.
193193
We'll fix this in the next section.
194194

195195
For now, have a browse around the GitHub web interface.
196196

197197
## 📄 Configuring repository to host docs on GitHub Pages
198198

199-
Now that your repository is on GitHub, you need to do a few more steps to set up your project's documentation website.
199+
Now that your repository is on GitHub, you need to do one more step to set up your project's documentation website.
200200
The HTML documentation will be built using the `Documentation` workflow (that we're going to fix) and hosted on [GitHub Pages](https://pages.github.com/).
201201

202202
If you scroll back in your terminal to the end of the [cookiecutter] questions, you should be able to find a message like:
203203

204204
```sh
205-
The 'Documentation' GitHub Actions workflow has been set up to push the built
206-
HTML documentation to a branch gh-pages on pushes to main for deploying as a
207-
GitHub Pages website. To allow the GitHub Actions bot to push to the gh-pages
208-
branch you need to enable 'Read and write permissions' under 'Workflow
209-
permissions' at
205+
The 'Documentation' GitHub Actions workflow has been set up to deploy the built
206+
HTML documentation to a GitHub Pages website on pushes to main.
210207

211-
https://github.com/{github_owner}/{project_slug}/settings/actions
212-
213-
After the 'Documentation' workflow has successfully completed at least once
214-
you will also need to configure the repository to deploy a GitHub pages site
215-
from the content on the gh-pages branch by going to
208+
You will need to configure the repository to deploy a GitHub pages site using
209+
GitHub Actions by going to
216210

217211
https://github.com/{github_owner}/{project_slug}/settings/pages
218212

219-
and under 'Built and deployment' selecting 'Deploy from a branch' for the
220-
'Source' drop-down and 'gh-pages' for the 'Branch' drop-down, leaving the
221-
branch path drop-down with its default value of '/ (root)'.
213+
and under 'Build and deployment' selecting 'GitHub Actions' for 'Source'.
222214
```
223215

224216
As before replace `{github_owner}` and `{project_slug}` with the relevant GitHub repository owner and project slug that you chose at the start.
225217

226-
The first part of the instructions explains how to set the permissions for GitHub Actions.
227-
This lets the Actions bot push the built HTML documentation to a branch `gh-pages` when you update the default `main` branch.
218+
Following tha instructions printed to the terminal, go to `https://github.com/{github_owner}/{project_slug}/settings/pages` and set GitHub Actions as the source for GitHub Pages.
228219

229-
- Go to the Actions settings page at the URL above (or via the repository `Settings` tab, then `Actions > General`).
230-
- Set `Workflow permissions` to `Read and write permissions`.
220+
- Set `Source` to `GitHub Actions`.
231221

232-
Now that the permissions have changed, we need to re-run the `Documentation` workflow.
222+
Now that the source settings has been changed, we need to re-run the `deploy` job in the `Documentation` workflow.
233223

234224
- Go back to the Actions page. Select the Actions button (in the top bar), or visit
235225
`https://github.com/{github_owner}/{project_slug}/actions`.
236226
- Click on the failing entry for the `Documentation` workflow.
237-
- Click on the `Re-run all jobs` button (top right of the page).
238-
239-
After the `Documentation` workflow finishes, a new `gh-pages` branch will be created containing only the HTML docs.
240-
241-
Following tha instructions printed to the terminal, go to `https://github.com/{github_owner}/{project_slug}/settings/pages` and set this branch as the source for GitHub Pages.
227+
- Click on the drop down ▼ symbol next to `Re-run jobs` button (top right of the page) and click `Re-run failed jobs`.
228+
- Click `Re-run jobs` button in dialogue box which appears which should list the `deploy` job as the failed job to re-run.
242229

243-
- Set `Source` to `Deploy from branch` and `Branch` to `gh-pages`.
244-
245-
This will start another new workflow called `pages-build-deployment` (in the Actions page).
246230
When it finishes, you can view your HTML docs at:
247231

248232
```sh
@@ -309,10 +293,10 @@ uv venv --python 3.11.6
309293
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
310294

311295
```sh
312-
uv pip install --editable ".[dev,docs,test]"
296+
uv sync --all-groups
313297
```
314298

315-
from the root of the project repository.
299+
from the root of the project repository. Note that `uv>=0.6.7` is required to use the `--group` option.
316300

317301
<details><summary>Using venv as an alternative to uv </summary> <!-- markdownlint-disable-line MD033 -->
318302

@@ -343,9 +327,11 @@ python -m pip install --upgrade pip
343327
Similar to `uv`, once the environment is active, you can install the package in editable mode as well as all dependencies:
344328

345329
```sh
346-
python -m pip install --editable ".[dev,docs,test]"
330+
python -m pip install --editable . --group dev --group docs --group test
347331
```
348332

333+
Note that `pip>=25.1` is required to use the `--group` option.
334+
349335
</details>
350336

351337
## 🧪 Running package tests locally

{{cookiecutter.project_slug}}/.github/workflows/docs.yml

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
pull_request:
88

99
jobs:
10-
docs:
10+
build:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- name: Checkout source
@@ -28,21 +28,27 @@ jobs:
2828

2929
- name: Install tox
3030
run: python -m pip install tox
31+
3132
- name: Build HTML documentation with tox
3233
run: tox -e docs
33-
{%- if cookiecutter.deploy_docs_to_github_pages %}
3434

35-
# Automatically deploy documentation to a GitHub Pages website on pushing to main.
36-
# Requires configuring the repository to deploy GitHub pages from a branch
37-
# gh-pages (https://tinyurl.com/gh-pages-from-branch), which will be created the
38-
# first time this workflow step is run.
39-
- name: Publish documentation on GitHub pages
40-
if: success() && github.event_name != 'pull_request'
41-
uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4
35+
- name: Upload built docs as artifact
36+
id: deployment
37+
uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa # v3
4238
with:
43-
github_token: ${{ '{{' }} secrets.GITHUB_TOKEN {{ '}}' }}
44-
publish_dir: site
45-
publish_branch: gh-pages
46-
user_name: "github-actions[bot]"
47-
user_email: "github-actions[bot]@users.noreply.github.com"
39+
path: site
40+
{% if cookiecutter.deploy_docs_to_github_pages %}
41+
deploy:
42+
environment:
43+
name: github-pages
44+
url: ${{ '{{' }} steps.deployment.outputs.page_url {{ '}}' }}
45+
permissions:
46+
pages: write
47+
id-token: write
48+
runs-on: ubuntu-latest
49+
needs: build
50+
steps:
51+
- name: Deploy to GitHub Pages
52+
id: deployment
53+
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4
4854
{%- endif %}

{{cookiecutter.project_slug}}/pyproject.toml

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,27 @@ requires = [
55
"setuptools-scm",
66
]
77

8+
[dependency-groups]
9+
dev = [
10+
"build",
11+
"mypy",
12+
"pre-commit",
13+
"ruff",
14+
"tox",
15+
"twine",
16+
]
17+
docs = [
18+
"mkdocs",
19+
"mkdocs-include-markdown-plugin",
20+
"mkdocs-material",
21+
"mkdocstrings",
22+
"mkdocstrings-python",
23+
]
24+
test = [
25+
"pytest",
26+
"pytest-cov",
27+
]
28+
829
[project]
930
authors = [
1031
{email = "{{cookiecutter.author_email}}", name = "{{cookiecutter.author_given_names}} {{cookiecutter.author_family_names}}"},
@@ -34,23 +55,6 @@ license-files = [
3455
"LICENSE.md",
3556
]
3657
name = "{{cookiecutter.project_slug}}"
37-
optional-dependencies = {dev = [
38-
"build",
39-
"mypy",
40-
"pre-commit",
41-
"ruff",
42-
"tox",
43-
"twine",
44-
], docs = [
45-
"mkdocs",
46-
"mkdocs-include-markdown-plugin",
47-
"mkdocs-material",
48-
"mkdocstrings",
49-
"mkdocstrings-python",
50-
], test = [
51-
"pytest",
52-
"pytest-cov",
53-
]}
5458
readme = "README.md"
5559
requires-python = ">={{cookiecutter.min_python_version}}"
5660
urls.homepage = "{{cookiecutter.__repo_url}}"
@@ -132,7 +136,7 @@ env_run_base = {commands = [
132136
"--cov",
133137
"--cov-report=xml",
134138
],
135-
], extras = [
139+
], dependency_groups = [
136140
"test",
137141
]}
138142
env.docs = {commands = [
@@ -141,7 +145,7 @@ env.docs = {commands = [
141145
"build",
142146
"--strict",
143147
],
144-
], extras = [
148+
], dependency_groups = [
145149
"docs",
146150
]}
147151
{%- for python_version in range(

0 commit comments

Comments
 (0)