Skip to content

Commit 6e5e2cc

Browse files
authored
Merge pull request #62 from per1234/update-python-infrastructure
Update infrastructure for linting and add for formatting Python files
2 parents 40d17d7 + 85ab6a2 commit 6e5e2cc

File tree

10 files changed

+621
-437
lines changed

10 files changed

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

.github/workflows/libraries_report-size-deltas.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,6 @@ jobs:
3838
poetry install \
3939
--no-root
4040
41-
- name: Lint with flake8
42-
run: |
43-
poetry run \
44-
flake8 \
45-
--config "${{ env.PYTHON_PROJECT_PATH }}/.flake8" \
46-
--show-source \
47-
"${{ env.PYTHON_PROJECT_PATH }}"
48-
4941
- name: Run Python unit tests and record code coverage data
5042
run: |
5143
export PYTHONPATH="${{ env.PYTHON_PROJECT_PATH }}"

README.md

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

33
[![Check npm status](https://github.com/arduino/report-size-deltas/actions/workflows/check-npm-task.yml/badge.svg)](https://github.com/arduino/report-size-deltas/actions/workflows/check-npm-task.yml)
44
[![Check Poetry status](https://github.com/arduino/report-size-deltas/actions/workflows/check-poetry-task.yml/badge.svg)](https://github.com/arduino/report-size-deltas/actions/workflows/check-poetry-task.yml)
5+
[![Check Python status](https://github.com/arduino/report-size-deltas/actions/workflows/check-python-task.yml/badge.svg)](https://github.com/arduino/report-size-deltas/actions/workflows/check-python-task.yml)
56
[![Check Taskfiles status](https://github.com/arduino/report-size-deltas/actions/workflows/check-taskfiles.yml/badge.svg)](https://github.com/arduino/report-size-deltas/actions/workflows/check-taskfiles.yml)
67
[![Tests](https://github.com/arduino/report-size-deltas/workflows/libraries/report-size-deltas%20workflow/badge.svg)](https://github.com/arduino/report-size-deltas/actions?workflow=libraries/report-size-deltas+workflow)
78
[![Integration Tests](https://github.com/arduino/report-size-deltas/actions/workflows/test-integration.yml/badge.svg)](https://github.com/arduino/report-size-deltas/actions/workflows/test-integration.yml)

Taskfile.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,16 @@ tasks:
1111
deps:
1212
- task: npm:validate
1313
- task: general:check-spelling
14+
- task: npm:validate
15+
- task: poetry:validate
16+
- task: python:lint
1417

1518
fix:
1619
desc: Make automated corrections to the project's files
1720
deps:
1821
- task: general:correct-spelling
22+
- task: poetry:sync
23+
- task: python:format
1924

2025
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/spell-check-task/Taskfile.yml
2126
general:check-spelling:
@@ -134,6 +139,22 @@ tasks:
134139
check \
135140
--lock
136141
142+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-python-task/Taskfile.yml
143+
python:format:
144+
desc: Format Python files
145+
deps:
146+
- task: poetry:install-deps
147+
cmds:
148+
- poetry run black .
149+
150+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-python-task/Taskfile.yml
151+
python:lint:
152+
desc: Lint Python code
153+
deps:
154+
- task: poetry:install-deps
155+
cmds:
156+
- poetry run flake8 --show-source
157+
137158
# Make a temporary file named according to the passed TEMPLATE variable and print the path passed to stdout
138159
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
139160
utility:mktemp-file:

poetry.lock

Lines changed: 92 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[tool.black]
2+
line-length = 120
3+
14
[tool.poetry]
25
name = "arduino/report-size-deltas"
36
version = "0.0.0"
@@ -8,6 +11,7 @@ authors = ["Arduino <info@arduino.cc>"]
811
python = "3.11.*"
912

1013
[tool.poetry.group.dev.dependencies]
14+
black = "23.11.0"
1115
codespell = "2.2.5"
1216
coverage = "7.3.3"
1317
flake8 = "6.1.0"

reportsizedeltas/.flake8

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

0 commit comments

Comments
 (0)