Skip to content

Commit 61be1f2

Browse files
committed
Add cookiecutter template variables description
The description of the variables will be printed before they are prompted when generating a new project, and will be also included in the documentation website. To show the help before the project generation we need to use a very dirty hack as cookiecutter doesn't support a hook that runs before the variables are printed. So to do that we hijack a cookiecutter variable itself ("Introduction") to display the help in the default text. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent a6a16c8 commit 61be1f2

File tree

5 files changed

+85
-0
lines changed

5 files changed

+85
-0
lines changed

cookiecutter/cookiecutter.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"Introduction": "{{cookiecutter | introduction}}",
23
"type": [
34
"actor",
45
"api",
@@ -25,6 +26,7 @@
2526
"jinja2_time.TimeExtension",
2627
"local_extensions.default_codeowners",
2728
"local_extensions.github_repo_name",
29+
"local_extensions.introduction",
2830
"local_extensions.keywords",
2931
"local_extensions.pypi_package_name",
3032
"local_extensions.python_package",

cookiecutter/local_extensions.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"""
99

1010
import json as _json
11+
import pathlib as _pathlib
1112

1213
from cookiecutter.utils import simple_filter as _simple_filter
1314

@@ -191,3 +192,30 @@ def default_codeowners(cookiecutter: dict[str, str]) -> str:
191192
assert repo_type in type_to_team, f"Unhandled repository type {repo_type!r}"
192193

193194
return type_to_team[repo_type]
195+
196+
197+
@_simple_filter # type: ignore[misc]
198+
def introduction(
199+
cookiecutter: dict[str, str] # pylint: disable=unused-argument
200+
) -> str:
201+
"""Build an introduction text for the project generation.
202+
203+
Args:
204+
cookiecutter: The cookiecutter context.
205+
206+
Returns:
207+
The introduction text.
208+
"""
209+
with (_pathlib.Path(__file__).parent / "variable-reference.md").open() as doc_file:
210+
variable_reference = doc_file.read()
211+
return f"""]
212+
213+
Welcome to repo-config Cookiecutter template!
214+
215+
This template will help you to create a new repository for your project. You will be asked to provide some information about your project.
216+
217+
Here is an explanation of what each variable is for and will be used for:
218+
219+
{variable_reference}
220+
221+
[Please press any key to continue"""

cookiecutter/variable-reference.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
* `type`: The type of repository. It must be chosen from the list.
2+
3+
* `name`: The name of the project. This will be used to build defaults for
4+
other inputs, such as `title`, `python_package`, etc. It should be one word,
5+
using only alphanumeric characters (and starting with a letter).
6+
7+
* `description`: A short description of the project. It will be used as the
8+
description in the `README.md`, `pyproject.toml`, `mkdocs.yml`, etc.
9+
10+
* `title`: A human-readable name or title for the project. It will be used in
11+
the `README.md`, `CONTRIBUTING.md`, and other files to refer to the project,
12+
as well as the site title in `mkdocs.yml`.
13+
14+
* `keywords`: A comma-separated list of keywords that will be used in the
15+
`pyproject.toml` file. If left untouched, it will use only some predefined
16+
keywords. If anything else is entered, it will be **added** to the default
17+
keywords.
18+
19+
* `github_org`: The GitHub handle of the organization where the project will
20+
reside. This will be used to generate links to the project on GitHub.
21+
22+
* `license`: Currently, only two options are provided: `MIT`, which should be
23+
used for open-source projects, and `Proprietary`, which should be used for
24+
closed-source projects. This will be added to file headers and used as the
25+
license in `pyproject.toml`.
26+
27+
* `author_name`, `author_email`: The name and email address of the author of
28+
the project. They will be used in the copyright notice in file headers and
29+
as the author in `pyproject.toml`.
30+
31+
* `python_package`: The Python package in which this project will reside. All
32+
files provided by this project should be located in this package. This needs
33+
to be a list of valid Python identifiers separated by dots. The source file
34+
structure will be derived from this. For example, `frequenz.actor.example`
35+
will generate files in `src/frequenz/actor/example`.
36+
37+
* `pypi_package_name`: The name of the PyPI/wheel/distribution package. This
38+
should be consistent with the `python_package`, usually replacing `.` with
39+
`-`. For example, `frequenz-actor-example`.
40+
41+
* `github_repo_name`: The handle of the GitHub repository where the project
42+
will reside. This will be used to generate links to the project on GitHub and
43+
as the top-level directory name.
44+
45+
* `default_codeowners`: A space-separated list of GitHub teams (`@org/team`) or
46+
users (`@user`) that will be the default code owners for this project. This
47+
will be used to build the `CODEOWNERS` file. Please refer to the [code owners
48+
documentation] for more details on the valid syntax.
49+
50+
[code owners documentation]: https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners

docs/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ After completing the project and fixing the `TODO`s, you can either amend the
4646
previous commit using `git commit --amend` or create a new commit for the
4747
changes using `git commit`.
4848

49+
### Template variables reference
50+
51+
--8<-- "cookiecutter/variable-reference.md"
52+
4953
### Create the local development environment
5054

5155
To start development, you need to make sure your environment is correctly set

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ plugins:
108108

109109
# Preview controls
110110
watch:
111+
- "cookiecutter/variable-reference.md"
111112
- "src"
112113
- README.md
113114
- CONTRIBUTING.md

0 commit comments

Comments
 (0)