Skip to content

Commit

Permalink
refactor(workflows): code formatting and linting
Browse files Browse the repository at this point in the history
Overhaul workflow (jobs) for code formatting and linting,
i.e. Black, Flake8, isort: set ENV variable for Python
version, make equivalent steps in individual jobs more
consistent, give every step a name, allow manual triggering
of workflow.
Use black profile for isort in setup.cfg to avoid redundancy.
Add SPDX identifiers.
  • Loading branch information
keikoro committed May 27, 2024
1 parent 945ec8d commit 12f346d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 33 deletions.
70 changes: 42 additions & 28 deletions .github/workflows/formatting_linting.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,69 @@
name: Code Format Check
# SPDX-FileCopyrightText: 2024 K Kollmann
# SPDX-License-Identifier: MIT

name: Code formatting and linting

on:
pull_request:
push:
branches:
- master
pull_request:
- main
workflow_dispatch:

env:
PYTHON_VERSION: "3.9"

jobs:
black:
name: Black code formatter
runs-on: ubuntu-latest
name: Black
steps:
- uses: actions/checkout@v4.1.6
- name: Set up Python
uses: actions/setup-python@v5.1.0
- name: Black
uses: psf/black@24.4.2 # already includes args "--check --diff"
- name: Checkout repo
uses: actions/checkout@v4.1.6
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Run Black
uses: psf/black@24.4.2
with:
options: "--version --check --diff --color" # default: "--check --diff"

flake8:
name: Flake8 linter
runs-on: ubuntu-latest
name: Flake8
steps:
- uses: actions/checkout@v4.1.6
- name: Set up Python
- name: Checkout repo
uses: actions/checkout@v4.1.6
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Set up Python environment – ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v5.1.0
with:
python-version: '3.9'
python-version: ${{ env.PYTHON_VERSION }}
- name: Install dependencies
run: |
python -m pip install --upgrade wheel pip
pip install .[lint]
- name: Lint examples
run: flake8 examples --show-source
- name: Lint scripts
run: flake8 setup.py docs/conf.py scripts --show-source
- name: Lint tests
run: flake8 tests --show-source
- name: Lint moviepy
run: flake8 moviepy --show-source
- name: Show Flake8 version
run: flake8 --version
- name: Run Flake8
run: flake8 -v --show-source moviepy setup.py scripts docs/conf.py examples tests

isort:
name: isort import sorter
runs-on: ubuntu-latest
name: isort
steps:
- uses: actions/checkout@v4.1.6
- name: Set up Python
- name: Checkout repo
uses: actions/checkout@v4.1.6
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Set up Python environment – ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v5.1.0
with:
python-version: '3.9'
python-version: ${{ env.PYTHON_VERSION }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install isort
- name: Check imports
run: isort --check-only moviepy tests examples docs/conf.py scripts
python -m pip install --upgrade wheel pip
pip install .[lint]
- name: Run isort
run: isort --check-only --diff moviepy setup.py scripts docs/conf.py examples tests
7 changes: 2 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,10 @@ docstring-convention = numpy
#max-complexity = 10

[isort]
profile = black
lines_after_imports = 2
multi_line_output = 3
line_length = 88
use_parentheses = True
combine_as_imports = True
include_trailing_comma = True
py_version = 36
py_version = 39
known_tests_third_party = pytest
sections = STDLIB,THIRDPARTY,TESTS_THIRD_PARTY,FIRSTPARTY,LOCALFOLDER

Expand Down

0 comments on commit 12f346d

Please sign in to comment.