cookiecutter gh:mrwegs/python-package-template --checkout masterIn this cookiecutter 🍪 template we combine state-of-the-art libraries and best development practices for Python.
- Supports
Python 3.9and higher. Poetryas a dependencies manager. See configuration inpyproject.toml.- Automatic codestyle with
black - Linting with
ruff - Type checks with
mypy, security checks withsafety. - Testing with
pytestandcoverage. - Ready-to-use
pre-commithooks with code-formatting. - Ready-to-use
.editorconfig,.dockerignore, and.gitignore.
Github Actionswith linters and tests in the workflow.Gitlab CIwith linters and tests in the pipeline.- Ready-to-use
Makefilewith formatting, linting, and testing. More details in makefile-usage. - Dockerfile for your package.
- docker-compose.yml for local developement in Docker.
To begin using the template consider updating cookiecutter
pip install -U cookiecutterthen go to a directory where you want to create your project and run:
cookiecutter gh:mrwegs/python-package-template --checkout masterTemplate generator will ask you to fill some variables.
The input variables, with their default values:
| Parameter | Default value | Description |
|---|---|---|
project_name |
python-project |
Check the availability of possible name before creating the project. |
project_description |
based on the project_name |
Brief description of your project. |
package_name |
based on the project_name |
Name of the python package with source code |
git_platform |
github |
Git platform (Github/Gitlab) |
username |
username |
User or organization name for Git platform |
git_repo_url |
based on git_platform, project_name and username |
URL to the git repository |
email |
based on the username |
To specify the ownership of the project in pyproject.toml. |
version |
0.1.0 |
Initial version of the package. Make sure it follows the Semantic Versions specification. |
python_version |
3.9 |
Python version. One of 3.9, 3.10, 3.11, 3.12. It is used for builds, CI and formatters. |
line_length |
88 | The max length per line (used for codestyle with black and isort). NOTE: This value must be between 50 and 300. |
All input values will be saved in the cookiecutter-config-file.yml file so that you won't lose them. 😉
Your project will contain README.md file with instructions for development, deployment, etc. You can read the project README.md template before.
By running make install
After you create a project, it will appear in your directory, and will display a message about how to initialize the project.
By running make pre-commit-install. Make sure to set up git first via git init.
Makefile contains a lot of functions for faster development.
1. Download and remove Poetry
To download and install Poetry run:
make poetry-downloadTo uninstall
make poetry-remove2. Install all dependencies and pre-commit hooks
Install requirements:
make installPre-commit hooks coulb be installed after git init via
make pre-commit-install3. Codestyle
Automatic formatting uses black and ruff
make codestyle
# or use synonym
make formatCodestyle checks only, without rewriting files:
make check-codestyleUpdate all dev libraries to the latest version using one comand
make update-dev-deps4. Code security
make check-safetyThis command launches Poetry integrity checks as well as identifies security issues with Safety
make check-safety5. Type checks
Run mypy static type checker
make mypy6. Tests with coverage
Run pytest
make test7. All linters
Of course there is a command to rule run all linters in one:
make lint8. Docker
make docker-buildwhich is equivalent to:
make docker-build VERSION=latestRemove docker image with
make docker-removeRun with docker compose
make docker-up9. Cleanup
Delete cache and build files:
make cleanupThis template was initially forked from the following template: