Skip to content

Commit 71b4fd2

Browse files
committed
Update infrastructure for checking for problems with Python code
Arduino tooling projects use a standardized infrastructure. A centralized collection of reusable infrastructure assets is maintained in a dedicated repository: https://github.com/arduino/tooling-project-assets Since the time this project's infrastructure was installed, some advancements have been made in the upstream "template" assets. The project's infrastructure is hereby brought up to date with the state of the art upstream assets. The significant changes: - Migration to the use of the Task task runner to allow contributors to easily run the same operations locally as is done by the CI system on GitHub. - The project will now be formatted using the Black code formatter tool, the standard for Arduino Tooling projects.
1 parent 4525fab commit 71b4fd2

File tree

8 files changed

+278
-75
lines changed

8 files changed

+278
-75
lines changed

.flake8

Lines changed: 12 additions & 0 deletions
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
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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/actions/using-workflows/events-that-trigger-workflows
5+
on:
6+
create:
7+
push:
8+
paths:
9+
- ".github/workflows/check-python-task.ya?ml"
10+
- "**/.flake8"
11+
- "**/poetry.lock"
12+
- "**/pyproject.toml"
13+
- "**/setup.cfg"
14+
- ".python-version"
15+
- "Taskfile.ya?ml"
16+
- "**/tox.ini"
17+
- "**.py"
18+
pull_request:
19+
paths:
20+
- ".github/workflows/check-python-task.ya?ml"
21+
- "**/.flake8"
22+
- "**/poetry.lock"
23+
- "**/pyproject.toml"
24+
- "**/setup.cfg"
25+
- ".python-version"
26+
- "Taskfile.ya?ml"
27+
- "**/tox.ini"
28+
- "**.py"
29+
schedule:
30+
# Run periodically to catch breakage caused by external changes.
31+
- cron: "0 8 * * WED"
32+
workflow_dispatch:
33+
repository_dispatch:
34+
35+
jobs:
36+
run-determination:
37+
runs-on: ubuntu-latest
38+
outputs:
39+
result: ${{ steps.determination.outputs.result }}
40+
steps:
41+
- name: Determine if the rest of the workflow should run
42+
id: determination
43+
run: |
44+
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
45+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
46+
if [[
47+
"${{ github.event_name }}" != "create" ||
48+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
49+
]]; then
50+
# Run the other jobs.
51+
RESULT="true"
52+
else
53+
# There is no need to run the other jobs.
54+
RESULT="false"
55+
fi
56+
57+
echo "result=$RESULT" >> $GITHUB_OUTPUT
58+
59+
lint:
60+
needs: run-determination
61+
if: needs.run-determination.outputs.result == 'true'
62+
runs-on: ubuntu-latest
63+
64+
steps:
65+
- name: Checkout repository
66+
uses: actions/checkout@v3
67+
68+
- name: Install Python
69+
uses: actions/setup-python@v4
70+
with:
71+
python-version-file: .python-version
72+
73+
- name: Install Poetry
74+
run: |
75+
pipx install \
76+
--python "$(which python)" \
77+
poetry
78+
79+
- name: Install Task
80+
uses: arduino/setup-task@v1
81+
with:
82+
repo-token: ${{ secrets.GITHUB_TOKEN }}
83+
version: 3.x
84+
85+
- name: Run flake8
86+
uses: liskin/gh-problem-matcher-wrap@v2
87+
with:
88+
linters: flake8
89+
run: task python:lint
90+
91+
formatting:
92+
needs: run-determination
93+
if: needs.run-determination.outputs.result == 'true'
94+
runs-on: ubuntu-latest
95+
96+
steps:
97+
- name: Checkout repository
98+
uses: actions/checkout@v3
99+
100+
- name: Install Python
101+
uses: actions/setup-python@v4
102+
with:
103+
python-version-file: .python-version
104+
105+
- name: Install Poetry
106+
run: |
107+
pipx install \
108+
--python "$(which python)" \
109+
poetry
110+
111+
- name: Install Task
112+
uses: arduino/setup-task@v1
113+
with:
114+
repo-token: ${{ secrets.GITHUB_TOKEN }}
115+
version: 3.x
116+
117+
- name: Format Python code
118+
run: task python:format
119+
120+
- name: Check formatting
121+
run: git diff --color --exit-code

.github/workflows/lint-python.yml

Lines changed: 0 additions & 66 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Check Action Metadata status](https://github.com/arduino/compile-sketches/actions/workflows/check-action-metadata-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-action-metadata-task.yml)
44
[![Tests](https://github.com/arduino/compile-sketches/workflows/Test%20Python%20code/badge.svg)](https://github.com/arduino/compile-sketches/actions?workflow=Test+Python+code)
5-
[![Lint](https://github.com/arduino/compile-sketches/workflows/Lint%20Python%20code/badge.svg)](https://github.com/arduino/compile-sketches/actions?workflow=Lint+Python+code)
5+
[![Check Python status](https://github.com/arduino/compile-sketches/actions/workflows/check-python-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-python-task.yml)
66
[![Spell Check](https://github.com/arduino/compile-sketches/workflows/Spell%20Check/badge.svg)](https://github.com/arduino/compile-sketches/actions?workflow=Spell+Check)
77
[![codecov](https://codecov.io/gh/arduino/compile-sketches/branch/main/graph/badge.svg?token=Uv6f1ebMZ4)](https://codecov.io/gh/arduino/compile-sketches)
88

Taskfile.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ tasks:
66
desc: Check for problems with the project
77
deps:
88
- task: action:validate
9+
- task: python:lint
10+
11+
fix:
12+
desc: Make automated corrections to the project's files
13+
deps:
14+
- task: python:format
915

1016
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-action-metadata-task/Taskfile.yml
1117
action:validate:
@@ -36,6 +42,36 @@ tasks:
3642
cmds:
3743
- npm install
3844

45+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/poetry-task/Taskfile.yml
46+
poetry:install-deps:
47+
desc: Install dependencies managed by Poetry
48+
run: when_changed
49+
cmds:
50+
- |
51+
poetry install \
52+
--no-root \
53+
{{if .POETRY_GROUPS}} --only {{.POETRY_GROUPS}} {{end}}
54+
55+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-python-task/Taskfile.yml
56+
python:format:
57+
desc: Format Python files
58+
deps:
59+
- task: poetry:install-deps
60+
vars:
61+
POETRY_GROUPS: dev
62+
cmds:
63+
- poetry run black .
64+
65+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-python-task/Taskfile.yml
66+
python:lint:
67+
desc: Lint Python code
68+
deps:
69+
- task: poetry:install-deps
70+
vars:
71+
POETRY_GROUPS: dev
72+
cmds:
73+
- poetry run flake8 --show-source
74+
3975
# Make a temporary file named according to the passed TEMPLATE variable and print the path passed to stdout
4076
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
4177
utility:mktemp-file:

compilesketches/.flake8

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)