Skip to content

[skip changelog] Sync "Check Python" CI workflow with template #1393

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# TODO: move this to pyproject.toml when supported: https://gitlab.com/pycqa/flake8/merge_requests/245
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-python/.flake8
# See: https://flake8.pycqa.org/en/latest/user/configuration.html
# The code style defined in this file is the official standardized style to be used in all Arduino tooling projects and
# should not be modified.

[flake8]
max-line-length = 120
doctests = True
ignore =
E741,
# W503 and W504 are mutually exclusive, so one or the other must be ignored.
# PEP 8 recommends line break before, so we keep W504.
# W503 and W504 are mutually exclusive. PEP 8 recommends line break before.
W503
max-complexity = 10
max-line-length = 120
select = E,W,F,C,N
86 changes: 86 additions & 0 deletions .github/workflows/check-python-task.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-python-task.md
name: Check Python

env:
# See: https://github.com/actions/setup-python/tree/v2#available-versions-of-python
PYTHON_VERSION: "3.9"

# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
on:
push:
paths:
- ".github/workflows/check-python-task.ya?ml"
- "**/.flake8"
- "**/poetry.lock"
- "**/pyproject.toml"
- "**/setup.cfg"
- "Taskfile.ya?ml"
- "**/tox.ini"
- "**.py"
pull_request:
paths:
- ".github/workflows/check-python-task.ya?ml"
- "**/.flake8"
- "**/poetry.lock"
- "**/pyproject.toml"
- "**/setup.cfg"
- "Taskfile.ya?ml"
- "**/tox.ini"
- "**.py"
workflow_dispatch:
repository_dispatch:

jobs:
lint:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install Python
uses: actions/setup-python@v2
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install Poetry
run: pip install poetry

- name: Install Task
uses: arduino/setup-task@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
version: 3.x

- name: Run flake8
uses: liskin/gh-problem-matcher-wrap@v1
with:
linters: flake8
run: task python:lint

formatting:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install Python
uses: actions/setup-python@v2
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install Poetry
run: pip install poetry

- name: Install Task
uses: arduino/setup-task@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
version: 3.x

- name: Format Python code
run: task python:format

- name: Check formatting
run: git diff --color --exit-code
38 changes: 0 additions & 38 deletions .github/workflows/python-lint.yaml

This file was deleted.

28 changes: 16 additions & 12 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,22 @@ tasks:
cmds:
- clang-format -i rpc/cc/arduino/cli/*/*/*.proto

# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-python-task/Taskfile.yml
python:format:
desc: Format Python files
deps:
- task: poetry:install-deps
cmds:
- poetry run black .

# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-python-task/Taskfile.yml
python:lint:
desc: Lint Python code
deps:
- task: poetry:install-deps
cmds:
- poetry run flake8 --show-source

build:
desc: Build the project
deps:
Expand Down Expand Up @@ -219,18 +235,6 @@ tasks:
- task: python:check
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@per1234 apparently this was left behind, If it's ok for you, I can open a new PR and fix this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

- task: protoc:check

python:check:
desc: Linting for Python files
cmds:
- poetry install --no-root
- poetry run flake8

python:format:
desc: Automatically formats Python files
cmds:
- poetry install --no-root
- poetry run black .

check-legacy:
desc: Check fmt and lint for the `legacy` package
cmds:
Expand Down
2 changes: 1 addition & 1 deletion docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ pytest test_lib.py::test_list
When editing any Python file in the project remember to run linting checks with:

```shell
task python:check
task python:lint
```

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