Skip to content

Commit 391df7e

Browse files
authored
Sync Python checks with "template" assets (#103)
We have assembled a collection of reusable project assets: https://github.com/arduino/tooling-project-assets These will be used in the repositories of all Arduino tooling projects. Some improvements and standardizations have been made in the upstream "template" assets for checking Python files. Those are introduced to this repository here. Notable: - Bump Python version used by the workflow from 3.8 to 3.9 - Add check for black formatting compliance - Bump black formatting tool dependency to ^21.7b0 - Add pep8-naming flake8 plugin to check for Python naming convention compliance - Add flake8 problem matcher to prominently surface linting violations in diffs, workflow run summary and logs
1 parent ad1e806 commit 391df7e

File tree

6 files changed

+154
-55
lines changed

6 files changed

+154
-55
lines changed

Diff for: .flake8

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +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+
16
[flake8]
27
doctests = True
3-
ignore =
4-
# W503 and W504 are mutually exclusive, so one or the other must be ignored.
5-
# PEP 8 recommends line break before, so we keep W504.
6-
W503
8+
# W503 and W504 are mutually exclusive. PEP 8 recommends line break before.
9+
ignore = W503
710
max-complexity = 10
811
max-line-length = 120
912
select = E,W,F,C,N

Diff for: .github/workflows/check-python-task.yml

+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

Diff for: .github/workflows/lint-python.yml

-40
This file was deleted.

Diff for: Taskfile.yml

+9-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ includes:
44
dist: ./DistTasks.yml
55

66
tasks:
7+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/poetry-task/Taskfile.yml
78
poetry:install-deps:
89
desc: Install dependencies managed by Poetry
910
cmds:
@@ -190,16 +191,20 @@ tasks:
190191
cmds:
191192
- task: python:lint
192193

194+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-python-task/Taskfile.yml
193195
python:lint:
194196
desc: Lint Python code
195-
cmds:
197+
deps:
196198
- task: poetry:install-deps
197-
- poetry run flake8
199+
cmds:
200+
- poetry run flake8 --show-source
198201

202+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-python-task/Taskfile.yml
199203
python:format:
200-
desc: Automatically formats Python files
201-
cmds:
204+
desc: Format Python files
205+
deps:
202206
- task: poetry:install-deps
207+
cmds:
203208
- poetry run black .
204209

205210
vars:

Diff for: poetry.lock

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

Diff for: pyproject.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ python-dateutil = "^2.8.1"
1313

1414
[tool.poetry.dev-dependencies]
1515
flake8 = "^3.9.2"
16-
black = "^21.5b1"
16+
black = "^21.7b0"
1717
mkdocs = "^1.2.1"
1818
mkdocs-material = "^7.1.8"
1919
mdx-truly-sane-lists = "^1.2"
2020
click = "<7.2"
2121
GitPython = "^3.1.1"
2222
mike = "^1.0.1"
23+
pep8-naming = "^0.12.1"
2324

2425
[tool.black]
2526
line-length = 120

0 commit comments

Comments
 (0)