Skip to content

Commit 4b79d5a

Browse files
authored
Keep versions up to date in the docs (#162)
Instead of hardcoding the version in the documentation, use the new macro variables to keep the documentation up to date. For examples showing how to invoke cookiecutter we use the current git reference (tag or branch) and for `pyproject.toml` dependencies we use a tag if we are at one, otherwise we use a Git URL pointing to the current branch. If there is no Git information, we just omit the version, so the latest version should be used by both. This PR also fixes a few small issues and prepares for the release. Fixes #138, refs #134.
2 parents 4ff31e1 + bff4d68 commit 4b79d5a

File tree

62 files changed

+925
-318
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+925
-318
lines changed

.github/workflows/ci.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,14 @@ jobs:
351351
VERSION: ${{ steps.mike-version.outputs.version }}
352352
TITLE: ${{ steps.mike-version.outputs.title }}
353353
ALIASES: ${{ steps.mike-version.outputs.aliases }}
354+
# This is not ideal, we need to define all these variables here
355+
# because we need to calculate all the repository version information
356+
# to be able to show the correct versions in the documentation when
357+
# building it.
358+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
359+
GITHUB_REPO: ${{ github.repository }}
360+
GIT_REF: ${{ github.ref }}
361+
GIT_SHA: ${{ github.sha }}
354362
run: |
355363
mike deploy --update-aliases --title "$TITLE" "$VERSION" $ALIASES
356364

CONTRIBUTING.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,30 @@ These are the steps to create a new release:
193193
eventually too).
194194

195195
7. Celebrate!
196+
197+
## Cross-Arch Testing
198+
199+
This project has built-in support for testing across multiple architectures.
200+
Currently, our CI conducts tests on `arm64` machines using QEMU emulation. We
201+
also have the flexibility to expand this support to include additional
202+
architectures in the future.
203+
204+
This project contains Dockerfiles that can be used in the CI to test the
205+
python package in non-native machine architectures, e.g., `arm64`. The
206+
Dockerfiles exist in the directory `.github/containers/nox-cross-arch`, and
207+
follow a naming scheme so that they can be easily used in build matrices in the
208+
CI, in `nox-cross-arch` job. The naming scheme is:
209+
210+
```
211+
<arch>-<os>-python-<python-version>.Dockerfile
212+
```
213+
214+
E.g.,
215+
216+
```
217+
arm64-ubuntu-20.04-python-3.11.Dockerfile
218+
```
219+
220+
If a Dockerfile for your desired target architecture, OS, and python version
221+
does not exist here, please add one before proceeding to add your options to
222+
the test matrix.

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ It offers:
1818

1919
## Supported Platforms
2020

21-
The following platforms are officially supported (test):
21+
The following platforms are officially supported (tested):
2222

2323
- **Python:** 3.11
2424
- **Operating System:** Ubuntu Linux 20.04
@@ -31,7 +31,7 @@ Cookiecutter](https://cookiecutter.readthedocs.io/en/stable/installation.html).
3131
It is normally available in any Linux distribution, but some have a very old
3232
version (for example, Ubuntu/Debian). You can [check which version your distro
3333
has on Repology](https://repology.org/project/cookiecutter/versions). You need
34-
**at least version 2.1.0**. To ensure you get an up-to-date version, you can
34+
**at least version 2.4.0**. To ensure you get an up-to-date version, you can
3535
always use `pip` and install it in a `venv`:
3636

3737
```console
@@ -48,14 +48,17 @@ directory will be created with the generated project name. For example:
4848

4949
```sh
5050
cd ~/devel
51-
cookiecutter gh:frequenz-floss/frequenz-repo-config-python \
52-
--directory=cookiecutter \
53-
--checkout v0.6.2
51+
cookiecutter gh:frequenz-floss/frequenz-repo-config-python --directory=cookiecutter
5452
```
5553

5654
This command will prompt you for the project type, name, and other
5755
configuration options, and it will generate the entire project for you.
5856

57+
It is recommended to use a released version, you can do that by adding the
58+
option `--checkout <version>` to the command above. You can check which is the
59+
latest version
60+
[here](https://github.com/frequenz-floss/frequenz-repo-config-python/releases/latest).
61+
5962
After completing the project and fixing the `TODO`s, you can either amend the
6063
previous commit using `git commit --amend` or create a new commit for the
6164
changes using `git commit`.

RELEASE_NOTES.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
## Summary
44

5-
<!-- Here goes a general summary of what this release is about -->
5+
This release focuses on improving the documentation generation and the CI. In particular it brings a new versioning scheme for the documentation that supports multiple development branches and exposes pre-releases.
66

77
## Upgrading
88

9-
<!-- Here goes notes on how to upgrade from previous versions, including deprecations and what they should be replaced with -->
10-
119
### Cookiecutter template
1210

11+
- The recommended `cookiecutter` version was bumped to 2.4.0 to avoid some buggy old versions.
12+
1313
- `mkdocs`
1414

1515
- The script `docs/mkdocstrings_autoapi.py` was moved to `docs/_scripts/mkdocstrings.py`.
@@ -39,7 +39,13 @@
3939

4040
## New Features
4141

42-
<!-- Here goes the main new features and examples or instructions on how to use them -->
42+
- `frequenz_repo_config.version`: New module to get the version information for a repository.
43+
- `frequnz_repo_config.github`: New module to interact with GitHub.
44+
- `frequenz.repo_config.mkdocs.mike`: New module to manage `mike` versions and aliases.
45+
- `frequenz.repo_config.cli`: New package to implement CLI commands.
46+
47+
- `frequenz.repo.config.cli.version.mike.info`: New command to print GitHub Action variables with for the current `mike` version.
48+
- `frequenz.repo.config.cli.version.mike.sort`: New command to sort `mike` versions file (`versions.json`).
4349

4450
### Cookiecutter template
4551

@@ -51,6 +57,8 @@
5157
- Make code annotations numbered. This is useful to hint about the order one should read the annotations.
5258
- Add a navigation footer to show previous and next pages. This is specially useful when reading the documentation in a mobile device since the navigation bar is hidden.
5359
- Updated dependencies.
60+
- The hooking of `mkdocstrings` to `macros` plugins is moved to a separate function to avoid the noise in the `define_env()` function.
61+
- Improve formatting of signatures to show the types.
5462
- We use a new `mike` versioning scheme:
5563
5664
- Versions now have a title with the full tag name for tags and includes the (short) commit SHA for branches so users can know exactly which version they are reading.
@@ -64,9 +72,9 @@
6472
- Add a CI job to *join* all `nox` runs, so only one branch protection rule needs to be used.
6573
- Dependabot now will check for updates monthly and on a random day and time. This is to avoid all repositories updating at the same time.
6674
67-
## Bug Fixes
75+
- Add a section about cross-arch testing to `CONTRIBUTING.md`.
6876
69-
<!-- Here goes notable bug fixes that are worth a special mention or explanation -->
77+
## Bug Fixes
7078
7179
### Cookiecutter template
7280

cookiecutter/{{cookiecutter.github_repo_name}}/.github/workflows/ci.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,14 @@ jobs:
376376
VERSION: ${{ steps.mike-version.outputs.version }}
377377
TITLE: ${{ steps.mike-version.outputs.title }}
378378
ALIASES: ${{ steps.mike-version.outputs.aliases }}
379+
# This is not ideal, we need to define all these variables here
380+
# because we need to calculate all the repository version information
381+
# to be able to show the correct versions in the documentation when
382+
# building it.
383+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
384+
GITHUB_REPO: ${{ github.repository }}
385+
GIT_REF: ${{ github.ref }}
386+
GIT_SHA: ${{ github.sha }}
379387
run: |
380388
mike deploy --update-aliases --title "$TITLE" "$VERSION" $ALIASES
381389

cookiecutter/{{cookiecutter.github_repo_name}}/CONTRIBUTING.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,30 @@ These are the steps to create a new release:
204204
eventually too).
205205

206206
7. Celebrate!
207+
208+
## Cross-Arch Testing
209+
210+
This project has built-in support for testing across multiple architectures.
211+
Currently, our CI conducts tests on `arm64` machines using QEMU emulation. We
212+
also have the flexibility to expand this support to include additional
213+
architectures in the future.
214+
215+
This project contains Dockerfiles that can be used in the CI to test the
216+
python package in non-native machine architectures, e.g., `arm64`. The
217+
Dockerfiles exist in the directory `.github/containers/nox-cross-arch`, and
218+
follow a naming scheme so that they can be easily used in build matrices in the
219+
CI, in `nox-cross-arch` job. The naming scheme is:
220+
221+
```
222+
<arch>-<os>-python-<python-version>.Dockerfile
223+
```
224+
225+
E.g.,
226+
227+
```
228+
arm64-ubuntu-20.04-python-3.11.Dockerfile
229+
```
230+
231+
If a Dockerfile for your desired target architecture, OS, and python version
232+
does not exist here, please add one before proceeding to add your options to
233+
the test matrix.

cookiecutter/{{cookiecutter.github_repo_name}}/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ TODO(cookiecutter): Improve the README file
1212

1313
## Supported Platforms
1414

15-
The following platforms are officially supported (test):
15+
The following platforms are officially supported (tested):
1616

1717
- **Python:** 3.11
1818
- **Operating System:** Ubuntu Linux 20.04

cookiecutter/{{cookiecutter.github_repo_name}}/docs/css/mkdocstrings.css renamed to cookiecutter/{{cookiecutter.github_repo_name}}/docs/_css/mkdocstrings.css

File renamed without changes.

cookiecutter/{{cookiecutter.github_repo_name}}/docs/css/style.css renamed to cookiecutter/{{cookiecutter.github_repo_name}}/docs/_css/style.css

File renamed without changes.

cookiecutter/{{cookiecutter.github_repo_name}}/docs/_scripts/macros.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,16 @@ def _slugify(text: str) -> str:
3333
return toc.slugify_unicode(text, "-") # type: ignore[attr-defined,no-any-return]
3434

3535

36-
def define_env(env: macros.MacrosPlugin) -> None:
37-
"""Define the hook to create macro functions for use in Markdown.
36+
def _hook_macros_plugin(env: macros.MacrosPlugin) -> None:
37+
"""Integrate the `mkdocs-macros` plugin into `mkdocstrings`.
38+
39+
This is a temporary workaround to make `mkdocs-macros` work with
40+
`mkdocstrings` until a proper `mkdocs-macros` *pluglet* is available. See
41+
https://github.com/mkdocstrings/mkdocstrings/issues/615 for details.
3842
3943
Args:
40-
env: The environment to define the macro functions in.
44+
env: The environment to hook the plugin into.
4145
"""
42-
# A variable to easily show an example code annotation from mkdocs-material.
43-
# https://squidfunk.github.io/mkdocs-material/reference/code-blocks/#adding-annotations
44-
env.variables["code_annotation_marker"] = _CODE_ANNOTATION_MARKER
45-
46-
# TODO(cookiecutter): Add any other macros, variables and filters here.
47-
48-
# The code below is a temporary workaround to make `mkdocs-macros` work with
49-
# `mkdocstrings` until a proper `mkdocs-macros` *pluglet* is available. See
50-
# https://github.com/mkdocstrings/mkdocstrings/issues/615 for details.
51-
5246
# get mkdocstrings' Python handler
5347
python_handler = env.conf["plugins"]["mkdocstrings"].get_handler("python")
5448

@@ -71,3 +65,19 @@ def render_convert(markdown: str, *args: Any, **kwargs: Any) -> Any:
7165

7266
# patch the method
7367
python_handler.update_env = patched_update_env
68+
69+
70+
def define_env(env: macros.MacrosPlugin) -> None:
71+
"""Define the hook to create macro functions for use in Markdown.
72+
73+
Args:
74+
env: The environment to define the macro functions in.
75+
"""
76+
# A variable to easily show an example code annotation from mkdocs-material.
77+
# https://squidfunk.github.io/mkdocs-material/reference/code-blocks/#adding-annotations
78+
env.variables["code_annotation_marker"] = _CODE_ANNOTATION_MARKER
79+
80+
# TODO(cookiecutter): Add any other macros, variables and filters here.
81+
82+
# This hook needs to be done at the end of the `define_env` function.
83+
_hook_macros_plugin(env)

0 commit comments

Comments
 (0)