57 lines
2.1 KiB
Markdown
Raw Normal View History

# Naive Python template
## Run it
Execute this template like so:
```
cookiecutter https://quico.space/Quico/py-cookiecutter-templates.git --directory 'python-naive'
```
Cookiecutter interactively prompts you for the following info, here with example answers:
```
project_slug [project-slug]: dockerhost-firewalld-update
Select rich_logging:
1 - yes
2 - no
Choose from 1, 2 [1]:
Select uses_config_ini:
1 - yes
2 - no
Choose from 1, 2 [1]:
```
2022-06-17 03:32:59 +02:00
Done, directory structure and files for your next Python project are ready for you to hit the ground running.
## Explanation and terminology
Your three answers translate as follows into rendered files.
1. The `project_slug` is used as a directory name for your Python project where spaces and underscores are replaced-with-dashes. It's also used for a few example variables where `we_use_underscores` instead.
```
.
└── dockerhost-firewalld-update
  ├── dockerhost-firewalld-update.py
  ├── examples
  │   └── config.ini.example
  ├── requirements.in
  └── requirements.txt
```
2. The `rich_logging` variable adds settings and examples that make ample use of the [Rich package](https://github.com/Textualize/rich/) for beautiful logging. You typically want this so it defaults to `yes`. Just hit `Enter` to confirm. The setting also adds necessary requirements.
3. With `uses_config_ini` you're getting a boat load of functions, presets, variables and examples that integrate a config.ini file via the `configparser` module.
## Result
### Enable Rich and configparser
Above example of a Python project with Rich and `configparser` enabled will give you a directory structure like this:
```
.
└── dockerhost-firewalld-update
  ├── dockerhost-firewalld-update.py
  ├── examples
  │   └── config.ini.example
  ├── requirements.in
  └── requirements.txt
```
You can see real-life example file content over at [examples/rich-and-config](examples/rich-and-config). Cookiecutter has generated all necessary dependencies with pinned versions and a `rich-and-config.py` script file to get you started.