Skip to content

Update infrastructure for linting and add for formatting Python files #62

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
Dec 20, 2023
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
12 changes: 12 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# 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]
doctests = True
# W503 and W504 are mutually exclusive. PEP 8 recommends line break before.
ignore = W503
max-complexity = 10
max-line-length = 120
select = E,W,F,C,N
122 changes: 122 additions & 0 deletions .github/workflows/check-python-task.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# 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/main#available-versions-of-python
PYTHON_VERSION: "3.11"

# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
on:
create:
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"
schedule:
# Run periodically to catch breakage caused by external changes.
- cron: "0 8 * * WED"
workflow_dispatch:
repository_dispatch:

jobs:
run-determination:
runs-on: ubuntu-latest
permissions: {}
outputs:
result: ${{ steps.determination.outputs.result }}
steps:
- name: Determine if the rest of the workflow should run
id: determination
run: |
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
if [[
"${{ github.event_name }}" != "create" ||
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
]]; then
# Run the other jobs.
RESULT="true"
else
# There is no need to run the other jobs.
RESULT="false"
fi

echo "result=$RESULT" >> $GITHUB_OUTPUT

lint:
needs: run-determination
if: needs.run-determination.outputs.result == 'true'
runs-on: ubuntu-latest
permissions:
contents: read

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

- name: Install Python
uses: actions/setup-python@v5
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@v3
with:
linters: flake8
run: task python:lint

formatting:
needs: run-determination
if: needs.run-determination.outputs.result == 'true'
runs-on: ubuntu-latest
permissions:
contents: read

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

- name: Install Python
uses: actions/setup-python@v5
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
8 changes: 0 additions & 8 deletions .github/workflows/libraries_report-size-deltas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@ jobs:
poetry install \
--no-root

- name: Lint with flake8
run: |
poetry run \
flake8 \
--config "${{ env.PYTHON_PROJECT_PATH }}/.flake8" \
--show-source \
"${{ env.PYTHON_PROJECT_PATH }}"

- name: Run Python unit tests and record code coverage data
run: |
export PYTHONPATH="${{ env.PYTHON_PROJECT_PATH }}"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

[![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)
[![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)
[![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)
[![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)
[![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)
[![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)
Expand Down
21 changes: 21 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ tasks:
deps:
- task: npm:validate
- task: general:check-spelling
- task: npm:validate
- task: poetry:validate
- task: python:lint

fix:
desc: Make automated corrections to the project's files
deps:
- task: general:correct-spelling
- task: poetry:sync
- task: python:format

# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/spell-check-task/Taskfile.yml
general:check-spelling:
Expand Down Expand Up @@ -134,6 +139,22 @@ tasks:
check \
--lock

# 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

# Make a temporary file named according to the passed TEMPLATE variable and print the path passed to stdout
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
utility:mktemp-file:
Expand Down
93 changes: 92 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[tool.black]
line-length = 120

[tool.poetry]
name = "arduino/report-size-deltas"
version = "0.0.0"
Expand All @@ -8,6 +11,7 @@ authors = ["Arduino <[email protected]>"]
python = "3.11.*"

[tool.poetry.group.dev.dependencies]
black = "23.11.0"
codespell = "2.2.5"
coverage = "7.3.3"
flake8 = "6.1.0"
Expand Down
7 changes: 0 additions & 7 deletions reportsizedeltas/.flake8

This file was deleted.

Loading