Template for Python Projects @okp4.
This repository holds the template for building python projects with a consistent set of standards across all okp4 python projects. We are convinced that the quality of the code depends on clear and consistent coding conventions, with an automated enforcement (CI).
This way, the template promotes:
- the use of conventional commits, semantic versionning and semantic releasing which automates the whole package release workflow including: determining the next version number, generating the release notes, and publishing the artifacts (project tarball, docker images, etc.)
- a uniform way for managing the project lifecycle (dependencies management, building, testing)
- KISS principles: simple for developers
- a consistent coding style
π¨ do not fork this repository as it is a template repository
- Click on Use this template
- Give a name to your project
- Wait until the first run of CI finishes
- Clone your new project and happy coding!
The repository targets python 3.9
and higher.
The repository uses Poetry as python packaging and dependency management. Be sure to have it properly installed before.
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
You can follow the link below on how to install and configure Docker on your local machine:
This template provides the following:
- poetry for dependency management.
- flake8 for linting python code.
- mypy for static type checks.
- pytest for unit testing.
- click to easily setup your project commands
The project is also configured to enforce code quality by declaring some CI workflows:
- conventional commits
- lint
- unit test
- semantic release
Project is built by poetry.
poetry install
poetry run my-app --help
Will give something like
Usage: my-app [OPTIONS] COMMAND [ARGS]...
OKP4 python template, program description.
Options:
--help Show this message and exit.
Commands:
main-cmd Does something interesting...
version Print the application version information
Example:
poetry run my-app main-cmd --name Sunshine
β οΈ Be sure to write code compliant with linters or else you'll be rejected by the CI.
Code linting is performed by flake8.
poetry run flake8 --count --show-source --statistics
Static type check is performed by mypy.
poetry run mypy .
To improve code quality, we use other linters in our workflows, if you don't want to be rejected by the CI, please check these additional linters.
Markdown linting is performed by markdownlint-cli.
markdownlint "**/*.md"
Docker linting is performed hadolint.
hadolint Dockerfile
β οΈ Be sure to write tests that succeed or else you'll be rejected by the CI.
Unit tests are performed by the pytest testing framework.
poetry run pytest -v
Build a local docker image using the following command line:
docker build -t my-app .
Once built, you can run the container locally with the following command line:
docker run -ti --rm my-app
Please check out OKP4 health files :