Skip to content

Commit 5a5be54

Browse files
committed
[skip-changelog] add linting infrastructure and apply formatting
1 parent 9f637f1 commit 5a5be54

File tree

8 files changed

+260
-3
lines changed

8 files changed

+260
-3
lines changed

.flake8

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[flake8]
2+
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
7+
max-complexity = 10
8+
max-line-length = 120
9+
select = E,W,F,C,N

.github/workflows/lint-python.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Lint Python code
2+
3+
on:
4+
push:
5+
paths:
6+
- "**.py"
7+
- ".flake8"
8+
- "pyproject.toml"
9+
- "Taskfile.yml"
10+
pull_request:
11+
paths:
12+
- "**.py"
13+
- ".flake8"
14+
- "pyproject.toml"
15+
- "Taskfile.yml"
16+
17+
jobs:
18+
lint-python:
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v2
24+
25+
- name: Install Taskfile
26+
uses: arduino/setup-task@v1
27+
with:
28+
repo-token: ${{ secrets.GITHUB_TOKEN }}
29+
version: 3.x
30+
31+
- name: Install Python
32+
uses: actions/setup-python@v2
33+
with:
34+
python-version: "3.8"
35+
36+
- name: Install Poetry
37+
run: pip install poetry
38+
39+
- name: Lint Python files
40+
run: task python:check

Taskfile.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ tasks:
5656
- "'{{.GOLINTBIN}}' {{.GOLINTFLAGS}} ./..."
5757
- task: docs:check
5858
- task: config:check
59+
- task: python:check
5960

6061
config:check:
6162
desc: Check linting of configuration and supporting files
@@ -67,6 +68,22 @@ tasks:
6768
cmds:
6869
- npx {{ .PRETTIER }} --write "**/*.{yml,yaml}"
6970

71+
python:check:
72+
cmds:
73+
- task: python:lint
74+
75+
python:lint:
76+
desc: Lint Python code
77+
cmds:
78+
- poetry install --no-root
79+
- poetry run flake8
80+
81+
python:format:
82+
desc: Automatically formats Python files
83+
cmds:
84+
- poetry install --no-root
85+
- poetry run black .
86+
7087
vars:
7188
PROJECT_NAME: "FirmwareUploader"
7289
DIST_DIR: "dist"

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTk
307307
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
308308
golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
309309
golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
310+
golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs=
310311
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
311312
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
312313
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=

poetry.lock

Lines changed: 181 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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,11 @@ python = "^3.8"
99
pytest = "6.1.2"
1010
invoke = "^1.5.0"
1111
semver = "^2.13.0"
12+
13+
[tool.poetry.dev-dependencies]
14+
flake8 = "^3.9.2"
15+
black = "^21.5b1"
16+
17+
[tool.black]
18+
line-length = 120
19+
target-version = ["py38"]

test/conftest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717

1818
import pathlib
1919
import platform
20-
import invoke.context
20+
import invoke.context
2121
import pytest
2222

23+
2324
@pytest.fixture(scope="function")
2425
def run_command(pytestconfig, working_dir):
2526
"""Provide a wrapper around invoke's `run` API so that every test will work in the same temporary folder.
@@ -56,4 +57,4 @@ def working_dir(tmpdir_factory):
5657
end. This way all the tests work in isolation.
5758
"""
5859
work_dir = tmpdir_factory.mktemp(basename="FirmwareUploaderTestWork")
59-
yield str(work_dir)
60+
yield str(work_dir)

0 commit comments

Comments
 (0)