Skip to content

Commit 1cfd3f3

Browse files
authored
Add template variables docs and warning about cookiecutter command (#94)
- Add cookiecutter template variables description (fixes #86) - Add a warning about the cookiecutter command (fixes #93)
2 parents 31d7efb + 5ab859d commit 1cfd3f3

File tree

7 files changed

+105
-6
lines changed

7 files changed

+105
-6
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* Bump SDK version to v0.22.0.
1717
* Capitalize project name in title and expand shortened words.
1818
* Add a few more default keywords.
19+
* Add variable reference documentation.
1920

2021
## Bug Fixes
2122

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/hooks/post_gen_project.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def to_named_tuple(dictionary: dict[Any, Any], /) -> Any:
3030
return namedtuple("Cookiecutter", filtered.keys())(*filtered.values())
3131

3232

33-
cookiecutter = to_named_tuple(_json.loads("""{{cookiecutter | tojson}}"""))
33+
cookiecutter = to_named_tuple(_json.loads(r"""{{cookiecutter | tojson}}"""))
3434

3535

3636
def main() -> None:

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: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,38 @@ Collecting cookiecutter
3131
...
3232
```
3333

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

3736
```sh
38-
cd ~/devel
39-
cookiecutter gh:frequenz-floss/frequenz-repo-config-python --directory=cookiecutter
37+
cookiecutter gh:frequenz-floss/frequenz-repo-config-python \
38+
--directory=cookiecutter
4039
```
4140

4241
This command will prompt you for the project type, name, and other
43-
configuration options, and it will generate the entire project for you.
42+
configuration options, and it will generate the entire project for you in a new
43+
subdirectory.
44+
45+
!!! warning
46+
47+
This command needs to be typed literally!
48+
49+
`frequenz-floss/frequenz-repo-config-python` is the GitHub repository with
50+
the cookiecutter template that will be downloaded, and
51+
`--directory=cookiecutter` is needed because the cookiecutter template
52+
doesn't live at the top-level of that repository, but in a subdirectory
53+
called `cookiecutter`.
54+
55+
All information about your project will be prompted interactively by that
56+
command.
4457

4558
After completing the project and fixing the `TODO`s, you can either amend the
4659
previous commit using `git commit --amend` or create a new commit for the
4760
changes using `git commit`.
4861

62+
### Template variables reference
63+
64+
--8<-- "cookiecutter/variable-reference.md"
65+
4966
### Create the local development environment
5067

5168
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)