From 9cb3ec672330ffbea2e4def977e2b92b8e1a4001 Mon Sep 17 00:00:00 2001 From: K Kollmann Date: Mon, 27 May 2024 17:43:38 +0200 Subject: [PATCH] refactor(workflows): code formatting and linting Overhaul workflow (jobs) for code formatting and linting, i.e. Black, Flake8, isort: rename file, allow manual triggering of workflow, set ENV variable for Python version, make equivalent steps in individual jobs more consistent, give every step a name. In setup.cfg, use black profile for isort to avoid redundancy; use same Python version as in workflow file. Add SPDX identifiers. --- .github/workflows/format_check.yml | 55 ------------------- .github/workflows/formatting_linting.yml | 69 ++++++++++++++++++++++++ setup.cfg | 7 +-- 3 files changed, 71 insertions(+), 60 deletions(-) delete mode 100644 .github/workflows/format_check.yml create mode 100644 .github/workflows/formatting_linting.yml diff --git a/.github/workflows/format_check.yml b/.github/workflows/format_check.yml deleted file mode 100644 index cb6273c63..000000000 --- a/.github/workflows/format_check.yml +++ /dev/null @@ -1,55 +0,0 @@ -name: Code Format Check - -on: - push: - branches: - - master - pull_request: - - -jobs: - black: - 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" - flake8: - runs-on: ubuntu-latest - name: Flake8 - steps: - - uses: actions/checkout@v4.1.6 - - name: Set up Python - uses: actions/setup-python@v5.1.0 - with: - python-version: '3.9' - - 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 - isort: - runs-on: ubuntu-latest - name: isort - steps: - - uses: actions/checkout@v4.1.6 - - name: Set up Python - uses: actions/setup-python@v5.1.0 - with: - python-version: '3.9' - - 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 diff --git a/.github/workflows/formatting_linting.yml b/.github/workflows/formatting_linting.yml new file mode 100644 index 000000000..e3d752426 --- /dev/null +++ b/.github/workflows/formatting_linting.yml @@ -0,0 +1,69 @@ +# SPDX-FileCopyrightText: 2024 K Kollmann +# SPDX-License-Identifier: MIT + +name: Code formatting and linting + +on: + pull_request: + push: + branches: + - master + - main + workflow_dispatch: + +env: + PYTHON_VERSION: "3.9" + +jobs: + black: + name: Black code formatter + runs-on: ubuntu-latest + steps: + - 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 + steps: + - 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: ${{ env.PYTHON_VERSION }} + - name: Install dependencies + run: | + python -m pip install --upgrade wheel pip + pip install .[lint] + - 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 + steps: + - 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: ${{ env.PYTHON_VERSION }} + - name: Install dependencies + run: | + 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 diff --git a/setup.cfg b/setup.cfg index 9abc16329..f524d3f25 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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