Skip to content

Commit 12f346d

Browse files
committed
refactor(workflows): code formatting and linting
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.
1 parent 945ec8d commit 12f346d

File tree

2 files changed

+44
-33
lines changed

2 files changed

+44
-33
lines changed

Diff for: .github/workflows/formatting_linting.yml

+42-28
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,69 @@
1-
name: Code Format Check
1+
# SPDX-FileCopyrightText: 2024 K Kollmann
2+
# SPDX-License-Identifier: MIT
3+
4+
name: Code formatting and linting
25

36
on:
7+
pull_request:
48
push:
59
branches:
610
- master
7-
pull_request:
11+
- main
12+
workflow_dispatch:
813

14+
env:
15+
PYTHON_VERSION: "3.9"
916

1017
jobs:
1118
black:
19+
name: Black code formatter
1220
runs-on: ubuntu-latest
13-
name: Black
1421
steps:
15-
- uses: actions/[email protected]
16-
- name: Set up Python
17-
uses: actions/[email protected]
18-
- name: Black
19-
uses: psf/[email protected] # already includes args "--check --diff"
22+
- name: Checkout repo
23+
uses: actions/[email protected]
24+
with:
25+
ref: ${{ github.event.pull_request.head.sha }}
26+
- name: Run Black
27+
28+
with:
29+
options: "--version --check --diff --color" # default: "--check --diff"
30+
2031
flake8:
32+
name: Flake8 linter
2133
runs-on: ubuntu-latest
22-
name: Flake8
2334
steps:
24-
- uses: actions/[email protected]
25-
- name: Set up Python
35+
- name: Checkout repo
36+
uses: actions/[email protected]
37+
with:
38+
ref: ${{ github.event.pull_request.head.sha }}
39+
- name: Set up Python environment – ${{ env.PYTHON_VERSION }}
2640
uses: actions/[email protected]
2741
with:
28-
python-version: '3.9'
42+
python-version: ${{ env.PYTHON_VERSION }}
2943
- name: Install dependencies
3044
run: |
3145
python -m pip install --upgrade wheel pip
3246
pip install .[lint]
33-
- name: Lint examples
34-
run: flake8 examples --show-source
35-
- name: Lint scripts
36-
run: flake8 setup.py docs/conf.py scripts --show-source
37-
- name: Lint tests
38-
run: flake8 tests --show-source
39-
- name: Lint moviepy
40-
run: flake8 moviepy --show-source
47+
- name: Show Flake8 version
48+
run: flake8 --version
49+
- name: Run Flake8
50+
run: flake8 -v --show-source moviepy setup.py scripts docs/conf.py examples tests
51+
4152
isort:
53+
name: isort import sorter
4254
runs-on: ubuntu-latest
43-
name: isort
4455
steps:
45-
- uses: actions/[email protected]
46-
- name: Set up Python
56+
- name: Checkout repo
57+
uses: actions/[email protected]
58+
with:
59+
ref: ${{ github.event.pull_request.head.sha }}
60+
- name: Set up Python environment – ${{ env.PYTHON_VERSION }}
4761
uses: actions/[email protected]
4862
with:
49-
python-version: '3.9'
63+
python-version: ${{ env.PYTHON_VERSION }}
5064
- name: Install dependencies
5165
run: |
52-
python -m pip install --upgrade pip
53-
pip install isort
54-
- name: Check imports
55-
run: isort --check-only moviepy tests examples docs/conf.py scripts
66+
python -m pip install --upgrade wheel pip
67+
pip install .[lint]
68+
- name: Run isort
69+
run: isort --check-only --diff moviepy setup.py scripts docs/conf.py examples tests

Diff for: setup.cfg

+2-5
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,10 @@ docstring-convention = numpy
4040
#max-complexity = 10
4141

4242
[isort]
43+
profile = black
4344
lines_after_imports = 2
44-
multi_line_output = 3
45-
line_length = 88
46-
use_parentheses = True
4745
combine_as_imports = True
48-
include_trailing_comma = True
49-
py_version = 36
46+
py_version = 39
5047
known_tests_third_party = pytest
5148
sections = STDLIB,THIRDPARTY,TESTS_THIRD_PARTY,FIRSTPARTY,LOCALFOLDER
5249

0 commit comments

Comments
 (0)