Skip to content

Commit 6b25a6d

Browse files
authored
Fix and improve documentation and generation (frequenz-floss#72)
- Treat mkdocs warnings as errors - Fix broken docs cross-references - Adjust docs text to 88 columns - Fix and sort project tags - Add instructions to initialize the docs site - Add advanced usage section pointing to the API - Add link to Frequenz website - Reestructure README headers - Move most of the README to docs/index.md - Add links to build status, PyPI package and docs website - Shorten the README and home title - Update RELEASE_NOTES - Speed up integration tests
2 parents 08ddf2a + c35b82e commit 6b25a6d

File tree

11 files changed

+342
-134
lines changed

11 files changed

+342
-134
lines changed

README.md

Lines changed: 32 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,135 +1,64 @@
1-
# Frequenz repository common configuration for Python
1+
# Frequenz Repository Configuration
22

3-
This is very opinionated set of tools and configurations to setup a Python
4-
repository for Frequenz projects.
3+
[![Build Status](https://github.com/frequenz-floss/frequenz-repo-config-python/actions/workflows/ci.yaml/badge.svg)](https://github.com/frequenz-floss/frequenz-repo-config-python/actions/workflows/ci.yaml)
4+
[![PyPI Package](https://img.shields.io/pypi/v/frequenz-repo-config)](https://pypi.org/project/frequenz-repo-config/)
5+
[![Docs](https://img.shields.io/badge/docs-latest-informational)](https://frequenz-floss.github.io/frequenz-repo-config-python/)
56

6-
If offers:
7+
## Introduction
78

8-
* [Cookiecutter] templates for scaffolding new projects
9-
* Trivial build of `noxfile.py` with some predefined sessions with all common
10-
checks.
11-
* Tools to build protobuf/grpc files as Python, including type information.
9+
This is a highly opinionated set of tools and configurations to set up a Python
10+
repository for [Frequenz](https://frequenz.com) projects.
1211

12+
It offers:
1313

14-
[Cookiecutter]: https://cookiecutter.readthedocs.io/en/stable
14+
* [Cookiecutter] templates for scaffolding new projects
15+
* Trivial build of `noxfile.py` with some predefined sessions that include all
16+
common checks.
17+
* Tools to build protobuf/grpc files as Python, including type information.
1518

16-
## Start a new project
19+
## Quick Example
1720

18-
To start a new project you should first [install
21+
To start a new project, you should first [install
1922
Cookiecutter](https://cookiecutter.readthedocs.io/en/stable/installation.html).
2023
It is normally available in any Linux distribution, but some have a very old
21-
version (for example, Ubuntu/Debian). You can [check which version your distro
22-
has in Repology](https://repology.org/project/cookiecutter/versions). You need
23-
**at least version 2.1.0**. To make sure to get an up to date version you can
24-
always uses `pip` and install in a `venv`:
24+
version (for example, Ubuntu/Debian). You can [check which version your distro
25+
has on Repology](https://repology.org/project/cookiecutter/versions). You need
26+
**at least version 2.1.0**. To ensure you get an up-to-date version, you can
27+
always use `pip` and install it in a `venv`:
2528

2629
```console
2730
$ python -m venv cookiecutter
2831
$ cd cookiecutter
2932
$ . bin/activate
30-
[cookiecutter] $ pip install cookiecutter
33+
(venv) $ pip install cookiecutter
3134
Collecting cookiecutter
3235
...
3336
```
3437

35-
Then just run cookiecutter where you want to create the new project. A new
38+
Then simply run [Cookiecutter] where you want to create the new project. A new
3639
directory will be created with the generated project name. For example:
3740

3841
```sh
3942
cd ~/devel
4043
cookiecutter gh:frequenz-floss/frequenz-repo-config-python --directory=cookiecutter
4144
```
4245

43-
This will prompt for the project type, name and other configuration and
44-
generate the whole project for you.
45-
46-
After completing it and fixing the TODOs
47-
you can amend the previous commit using `git commit --amend`
48-
or create a new commit for the changes using `git commit`.
49-
You can make sure linting and tests pass by creating a virtual
50-
environment, installing the development dependencies and running `nox`:
51-
```sh
52-
# requires at least python version 3.11
53-
python3 -m venv .venv
54-
. .venv/bin/activate
55-
pip install .[dev-noxfile]
56-
nox
57-
```
58-
59-
## Migrating an existing project
60-
61-
The easiest way to migrate an existing project is to just generate a new one
62-
basing all the inputs in the current project metadata and then overwritting the
63-
existing files.
64-
65-
It is recommended to commit all changes before doing this, so you can then use
66-
`git` to look at the changes.
67-
68-
If you generate the new repo in a temporary directory, you can easily overwrite
69-
the files in your existing project by using `rsync` or similar tools:
70-
71-
```sh
72-
cd /tmp
73-
cookiecutter gh:frequenz-floss/frequenz-repo-config-python --directory=cookiecutter
74-
rsync -vr --exclude=.git/ new-project/ /path/to/existing/project
75-
cd /path/to/existing/project
76-
git diff
77-
# Fix all the `TODO`s and cleanup the generated files
78-
git commit -a
79-
```
46+
This command will prompt you for the project type, name, and other
47+
configuration options, and it will generate the entire project for you.
8048

81-
!!! warning
49+
After completing the project and fixing the `TODO`s, you can either amend the
50+
previous commit using `git commit --amend` or create a new commit for the
51+
changes using `git commit`.
8252

83-
The trailing slash in `new-project/` and the lack of it in
84-
`/path/to/existing/project` are meaningful to `rsync`.
53+
## Documentation
8554

86-
Also make sure to **exclude** the `.git/` directory to avoid messing up
87-
with your local git repository.
88-
89-
## Update an existing project
90-
91-
To update an existing project you can use the [Cookiecutter *replay
92-
file*](https://cookiecutter.readthedocs.io/en/stable/advanced/replay.html) that
93-
was saved during the project generation. The file is saved in
94-
`.cookiecutter-replay.json`. Using this file you can re-run Cookiecutter
95-
without having to enter all the inputs again.
96-
97-
!!! warning
98-
99-
Don't forget to commit all changes in your repository before doing this!
100-
Files will be overwritten!
101-
102-
```sh
103-
git commit -a # commit all changes
104-
cd ..
105-
cookiecutter gh:frequenz-floss/frequenz-repo-config-python \
106-
--directory=cookiecutter \
107-
--force \
108-
--replay \
109-
--replay-file project-directory/.cookiecutter-replay.json
110-
```
111-
112-
This will create a new commit with all the changes to the overwritten files.
113-
Bear in mind that all the `TODO`s will come back, so there will be quite a bit
114-
of cleanup to do. You can easily check what was changed using `git show`, and
115-
you can use `git commit --amend` to amend the previous commit with the template
116-
updates, or create a new commit with the fixes. You can also use `git citool`
117-
or `git gui` to easily add, remove or even discard (revert) changes in the
118-
templates update commit.
119-
120-
!!! note
121-
122-
The `project-directory` is the directory of your previously generated
123-
project. If you renamed it, then the files will be generated in a new
124-
directory with the original name. You can update the target directory in
125-
the replay file.
126-
127-
!!! note
128-
129-
Please remember to keep your replay file up to date if you change any
130-
metadata in the project.
55+
For more detailed documentation, please check the [project's
56+
website](https://frequenz-floss.github.io/frequenz-repo-config-python/).
13157

13258
## Contributing
13359

13460
If you want to know how to build this project and contribute to it, please
135-
check out the [Contributing Guide](CONTRIBUTING.md).
61+
refer to the [Contributing Guide](CONTRIBUTING.md).
62+
63+
64+
[Cookiecutter]: https://cookiecutter.readthedocs.io/en/stable

RELEASE_NOTES.md

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,39 @@
22

33
## Summary
44

5-
<!-- Here goes a general summary of what this release is about -->
5+
This release is a major step and adds many features and breaking changes.
66

77
## Upgrading
88

9-
<!-- Here goes notes on how to upgrade from previous versions, including deprecations and what they should be replaced with -->
9+
Since this project is still in heavy development, the easiest way to upgrade is
10+
to regenerate the templates. Please follow the instructions in the new
11+
documentation website about [updating
12+
projects](https://frequenz-floss.github.io/frequenz-repo-config-python/next/#update-an-existing-project).
1013

1114
## New Features
1215

13-
<!-- Here goes the main new features and examples or instructions on how to use them -->
16+
This is just a quick (non-comprehensive) summary of the new features:
17+
18+
* Add `--diff` as a default argument for `isort`
19+
* Improve `README`
20+
* Don't import modules into packages
21+
* Support migrating and updating existing projects with Cookiecutter
22+
* Cookiecutter template
23+
24+
* Add `dependabot` configuration
25+
* Add issue templates, keyword labeler, and PR labeler
26+
* Add `CODEOWNERS` file
27+
* Add `direnv`-related files to `.gitignore`
28+
* Add GitHub CI workflow to `cookiecutter`
29+
* Add `CONTRIBUTING` guide to `cookiecutter`
30+
* Add `RELEASE_NOTES` to `cookiecutter`
31+
* Add support to generate documentation using `mkdocs`
32+
33+
* Apply all the Cookiecutter template improvements to this project
1434

1535
## Bug Fixes
1636

17-
<!-- Here goes notable bug fixes that are worth a special mention or explanation -->
37+
This is just a quick (non-comprehensive) summary of bug fixes:
38+
39+
* Fix some comments about creating labels
40+
* Fix tests

cookiecutter/hooks/post_gen_project.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,28 @@ def main() -> None:
6666
print(". .venv/bin/activate")
6767
print("pip install .[dev-noxfile]")
6868
print("nox")
69-
print("# To generate and serve the documentation:")
69+
print()
70+
print("To generate and serve the documentation:")
7071
print("pip install .[dev-mkdocs]")
7172
if cookiecutter.type == "api":
7273
print("# Requires docker")
7374
print("mkdocs serve")
7475
print()
76+
print("To initialize the GitHub pages website:")
77+
print("mike deploy --update-aliases next latest")
78+
print("mike set-default latest")
79+
print("git push upstream gh-pages # or origin if you haven't forked the repo")
80+
print()
81+
print("Make sure that GitHub pages is enabled in your repository settings:")
82+
print(
83+
f"https://github.com/{cookiecutter.github_org}/{cookiecutter.github_repo_name}"
84+
"/settings/pages"
85+
)
86+
print("If all went well, your new website should be available soon at:")
87+
print(
88+
f"https://{cookiecutter.github_org}.github.io/{cookiecutter.github_repo_name}/"
89+
)
90+
print()
7591
if warnings := do_sanity_checks():
7692
for warning in warnings:
7793
warn(warning)
@@ -80,7 +96,9 @@ def main() -> None:
8096
"If you had any issues or find any errors in the generated files, "
8197
"please report them!"
8298
)
83-
note("https://github.com/frequenz-floss/frequenz-repo-config-python/issues/new")
99+
note(
100+
"https://github.com/frequenz-floss/frequenz-repo-config-python/issues/new/choose"
101+
)
84102
print()
85103

86104

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# {{cookiecutter.title}}
22

3+
[![Build Status](https://github.com/{{cookiecutter.github_org}}/{{cookiecutter.github_repo_name}}/actions/workflows/ci.yaml/badge.svg)](https://github.com/{{cookiecutter.github_org}}/{{cookiecutter.github_repo_name}}/actions/workflows/ci.yaml)
4+
[![PyPI Package](https://img.shields.io/pypi/v/{{cookiecutter.pypi_package_name}})](https://pypi.org/project/{{cookiecutter.pypi_package_name}}/)
5+
[![Docs](https://img.shields.io/badge/docs-latest-informational)](https://{{cookiecutter.github_org}}.github.io/{{cookiecutter.github_repo_name}}/)
6+
7+
## Introduction
8+
39
{{cookiecutter.description}}
410

511
TODO(cookiecutter): Improve the README file

cookiecutter/{{cookiecutter.github_repo_name}}/mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ repo_url: "https://github.com/{{cookiecutter.github_org}}/{{cookiecutter.github_
1111
# TODO(cookiecutter): "main" is the GitHub repo default branch, you might want to update it
1212
# if the project uses a different default branch.
1313
edit_uri: "edit/main/docs/"
14+
strict: true # Treat warnings as errors
1415

1516
# Build directories
1617
theme:

0 commit comments

Comments
 (0)