Run flake8 and black on the Python files of the repository.
This is the version of the workflow for projects using the Task task runner tool.
Install the check-python-task.yml
GitHub Actions workflow to .github/workflows/
.flake8
- flake8 configuration file.- Install to: repository root
Taskfile.yml
- Python linting and formatting tasks.- Install to: repository root (or merge into the existing
Taskfile.yml
).
- Install to: repository root (or merge into the existing
Taskfile.yml
- Installation task.- Merge into
Taskfile.yml
- Merge into
The code style defined in pyproject.toml
and .flake8
is the official standardized style to be used in all Arduino tooling projects and should not be modified.
The tool dependencies of this workflow are managed by Poetry.
Install Poetry by following these instructions:
https://python-poetry.org/docs/#installation
If your project does not already use Poetry, you can initialize the pyproject.toml
file using these commands:
poetry init --python="^3.9" --dev-dependency="black@^25.1.0" --dev-dependency="flake8@^7.2.0" --dev-dependency="pep8-naming@^0.14.1"
poetry install
If already using Poetry, add the tool using this command:
poetry add --dev "black@^25.1.0" "flake8@^7.2.0" "pep8-naming@^0.14.1"
Commit the resulting pyproject.toml
and poetry.lock
files.
Set the version of Python used by the project in the env.PYTHON_VERSION
field of check-python-task.yml
.
Add the following to pyproject.toml
:
[tool.black]
line-length = 120
The black
configuration is the official standardized style to be used in all Arduino tooling projects and should not be modified.
Markdown badge:
[](https://github.com/TODO_REPO_OWNER/TODO_REPO_NAME/actions/workflows/check-python-task.yml)
Replace the TODO_REPO_OWNER
and TODO_REPO_NAME
placeholders in the URLs with the final repository owner and name (example).
Asciidoc badge:
image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-python-task.yml/badge.svg["Check Python status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-python-task.yml"]
Define the {repository-owner}
and {repository-name}
attributes and use them throughout the readme (example).
Add CI workflow to lint and check formatting of Python files
On every push and pull request that affects relevant files, run flake8 to check the Python files of
the repository for issues and black to check formatting.
The .flake8 file is used to configure flake8:
https://flake8.pycqa.org/en/latest/user/configuration.html
On every push and pull request that affects relevant files, run [`flake8`](https://flake8.pycqa.org/) to check the Python files of the repository for issues and [black](https://github.com/psf/black) to check formatting.
The `.flake8` file is used to configure `flake8`:
https://flake8.pycqa.org/en/latest/user/configuration.html