Skip to content
/ template-python Public template
generated from okp4/template-oss

πŸ–¨ Template for Python Projects @okp4.

License

Notifications You must be signed in to change notification settings

okp4/template-python

Python Project Template

Template for Python Projects @okp4.

version lint build test codecov conventional commits semantic-release contributor covenant License

Purpose & Philosophy

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

How to use

🚨 do not fork this repository as it is a template repository

  1. Click on Use this template
  2. Give a name to your project
  3. Wait until the first run of CI finishes
  4. Clone your new project and happy coding!

System requirements

Python

The repository targets python 3.9 and higher.

Poetry

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 -

Docker

You can follow the link below on how to install and configure Docker on your local machine:

What's included

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

Everyday activity

Build

Project is built by poetry.

poetry install

Usage

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

Lint

⚠️ 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

Unit Test

⚠️ 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 & run docker image (locally)

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

You want to get involved? 😍

Please check out OKP4 health files :