Skip to content

Commit 5353d4f

Browse files
committed
Add CI workflow to lint and check formatting of Python files
On every push and pull request that affects relevant files, and periodically, 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
1 parent c1d0f44 commit 5353d4f

File tree

7 files changed

+339
-4
lines changed

7 files changed

+339
-4
lines changed

.flake8

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-python/.flake8
2+
# See: https://flake8.pycqa.org/en/latest/user/configuration.html
3+
# The code style defined in this file is the official standardized style to be used in all Arduino tooling projects and
4+
# should not be modified.
5+
6+
[flake8]
7+
doctests = True
8+
# W503 and W504 are mutually exclusive. PEP 8 recommends line break before.
9+
ignore = W503
10+
max-complexity = 10
11+
max-line-length = 120
12+
select = E,W,F,C,N
+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-python-task.md
2+
name: Check Python
3+
4+
# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
5+
on:
6+
push:
7+
paths:
8+
- ".github/workflows/check-python-task.ya?ml"
9+
- "**/.flake8"
10+
- "**/poetry.lock"
11+
- "**/pyproject.toml"
12+
- "**/setup.cfg"
13+
- "Taskfile.ya?ml"
14+
- "**/tox.ini"
15+
- "**.py"
16+
pull_request:
17+
paths:
18+
- ".github/workflows/check-python-task.ya?ml"
19+
- "**/.flake8"
20+
- "**/poetry.lock"
21+
- "**/pyproject.toml"
22+
- "**/setup.cfg"
23+
- "Taskfile.ya?ml"
24+
- "**/tox.ini"
25+
- "**.py"
26+
workflow_dispatch:
27+
repository_dispatch:
28+
29+
jobs:
30+
lint:
31+
runs-on: ubuntu-latest
32+
33+
steps:
34+
- name: Checkout repository
35+
uses: actions/checkout@v2
36+
37+
- name: Install Python
38+
uses: actions/setup-python@v2
39+
with:
40+
python-version: "3.9"
41+
42+
- name: Install Poetry
43+
run: pip install poetry
44+
45+
- name: Install Task
46+
uses: arduino/setup-task@v1
47+
with:
48+
repo-token: ${{ secrets.GITHUB_TOKEN }}
49+
version: 3.x
50+
51+
- name: Run flake8
52+
run: task python:lint
53+
54+
formatting:
55+
runs-on: ubuntu-latest
56+
57+
steps:
58+
- name: Checkout repository
59+
uses: actions/checkout@v2
60+
61+
- name: Install Python
62+
uses: actions/setup-python@v2
63+
with:
64+
python-version: "3.9"
65+
66+
- name: Install Poetry
67+
run: pip install poetry
68+
69+
- name: Install Task
70+
uses: arduino/setup-task@v1
71+
with:
72+
repo-token: ${{ secrets.GITHUB_TOKEN }}
73+
version: 3.x
74+
75+
- name: Format Python code
76+
run: task python:format
77+
78+
- name: Check formatting
79+
run: git diff --color --exit-code

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
[![Sync Labels status](https://github.com/arduino/tooling-project-assets/actions/workflows/sync-labels.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/sync-labels.yml)
1414
[![Check Workflows status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-workflows-task.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-workflows-task.yml)
1515
[![Spell Check status](https://github.com/arduino/tooling-project-assets/actions/workflows/spell-check-task.yml/badge.svg)](https:/github.com/arduino/tooling-project-assets/actions/workflows/spell-check-task.yml)
16+
[![Check Python status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-python-task.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-python-task.yml)
1617

1718
The [Arduino](https://www.arduino.cc/) Tooling Team's collection of reusable project infrastructure assets.
1819

Taskfile.yml

+16
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,22 @@ tasks:
214214
cmds:
215215
- poetry update
216216

217+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-python-task/Taskfile.yml
218+
python:lint:
219+
desc: Lint Python code
220+
deps:
221+
- task: poetry:install-deps
222+
cmds:
223+
- poetry run flake8 --show-source
224+
225+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-python-task/Taskfile.yml
226+
python:format:
227+
desc: Format Python files
228+
deps:
229+
- task: poetry:install-deps
230+
cmds:
231+
- poetry run black .
232+
217233
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-yaml-task/Taskfile.yml
218234
yaml:lint:
219235
desc: Check for problems with YAML files

poetry.lock

+224-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)