Skip to content

Commit 7989a4e

Browse files
authored
[skip changelog] Sync "Check Python" CI workflow with template (#1393)
* [skip changelog] Sync "Check Python" CI workflow with template We have assembled a collection of reusable project assets: https://github.com/arduino/tooling-project-assets These assets will be used in the repositories of all Arduino tooling projects. Some minor improvements and standardizations have been made in the upstream "template" assets, and those are introduced to this repository here. Notable: - Check for black formatting style compliance - Update tool dependencies - Standardize linting task name and deprecate old task name - Add cyclomatic complexity check - Add pep8-naming plugin to flake8 * [skip changelog] Restore formatting compliance of Python code after black update After updating the black formatter tool, the new version wanted a small change in the Python formatting. * Remove obsolete Python linting task The sync with the template documentation assets has resulted in new standardized names for some of the tasks. The `python:check` task has been renamed to `python:lint`
1 parent ab31c21 commit 7989a4e

File tree

8 files changed

+247
-155
lines changed

8 files changed

+247
-155
lines changed

.flake8

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
# TODO: move this to pyproject.toml when supported: https://gitlab.com/pycqa/flake8/merge_requests/245
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.
25

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

.github/workflows/python-lint.yaml

-38
This file was deleted.

Taskfile.yml

+16-12
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,22 @@ tasks:
189189
cmds:
190190
- clang-format -i rpc/cc/arduino/cli/*/*/*.proto
191191

192+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-python-task/Taskfile.yml
193+
python:format:
194+
desc: Format Python files
195+
deps:
196+
- task: poetry:install-deps
197+
cmds:
198+
- poetry run black .
199+
200+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-python-task/Taskfile.yml
201+
python:lint:
202+
desc: Lint Python code
203+
deps:
204+
- task: poetry:install-deps
205+
cmds:
206+
- poetry run flake8 --show-source
207+
192208
build:
193209
desc: Build the project
194210
deps:
@@ -219,18 +235,6 @@ tasks:
219235
- task: python:check
220236
- task: protoc:check
221237

222-
python:check:
223-
desc: Linting for Python files
224-
cmds:
225-
- poetry install --no-root
226-
- poetry run flake8
227-
228-
python:format:
229-
desc: Automatically formats Python files
230-
cmds:
231-
- poetry install --no-root
232-
- poetry run black .
233-
234238
check-legacy:
235239
desc: Check fmt and lint for the `legacy` package
236240
cmds:

docs/CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ pytest test_lib.py::test_list
212212
When editing any Python file in the project remember to run linting checks with:
213213

214214
```shell
215-
task python:check
215+
task python:lint
216216
```
217217

218218
This will run `flake8` automatically and return any error in the code formatting, if not already installed it will also

0 commit comments

Comments
 (0)