From e03e960249d06de3e7a07d9aba0bf0e9d1b1fa5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Thu, 14 Mar 2024 14:05:09 +0100 Subject: [PATCH] Reorganize github workflows: one check on push+pr, one check+format then commit, only on push on master --- .github/workflows/autoblack.yml | 36 ------------------- .../{python_lint.yml => python-check.yml} | 16 ++++----- .github/workflows/python-format.yml | 32 +++++++++++++++++ pyproject.toml | 21 +++++++++++ 4 files changed, 61 insertions(+), 44 deletions(-) delete mode 100644 .github/workflows/autoblack.yml rename .github/workflows/{python_lint.yml => python-check.yml} (51%) create mode 100644 .github/workflows/python-format.yml create mode 100644 pyproject.toml diff --git a/.github/workflows/autoblack.yml b/.github/workflows/autoblack.yml deleted file mode 100644 index 8a1da50..0000000 --- a/.github/workflows/autoblack.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: Check / auto apply Black -on: - push: - branches: - - master - -jobs: - black: - name: Check / auto apply black - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Check files using the black formatter - uses: psf/black@stable - id: black - with: - options: "." - continue-on-error: true - - shell: pwsh - id: check_files_changed - run: | - # Diff HEAD with the previous commit - $diff = git diff - $HasDiff = $diff.Length -gt 0 - Write-Host "::set-output name=files_changed::$HasDiff" - - name: Create Pull Request - if: steps.check_files_changed.outputs.files_changed == 'true' - uses: peter-evans/create-pull-request@v6 - with: - token: ${{ secrets.GITHUB_TOKEN }} - title: "Format Python code with Black" - commit-message: ":art: Format Python code with Black" - body: | - This pull request uses the [psf/black](https://github.com/psf/black) formatter. - base: ${{ github.head_ref }} # Creates pull request onto pull request or commit branch - branch: actions/black diff --git a/.github/workflows/python_lint.yml b/.github/workflows/python-check.yml similarity index 51% rename from .github/workflows/python_lint.yml rename to .github/workflows/python-check.yml index b84305a..9b7dabb 100644 --- a/.github/workflows/python_lint.yml +++ b/.github/workflows/python-check.yml @@ -1,9 +1,9 @@ -name: Python Ruff Lint and commit +name: Python Lint with Ruff and Mypy on: + pull_request: push: branches: [master] - pull_request: jobs: ruff: @@ -12,14 +12,14 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 - - name: Install Ruff + - name: Install Ruff and Mypy run: pip install ruff - - name: Ruff check and fix + - name: Ruff check run: | ruff check . - ruff fix . - - uses: stefanzweifel/git-auto-commit-action@v4 - with: - commit_message: 'Python style fixes from Ruff' + - name: mypy check + run: | + yes | mypy src --install-types || true + mypy . diff --git a/.github/workflows/python-format.yml b/.github/workflows/python-format.yml new file mode 100644 index 0000000..c1199e1 --- /dev/null +++ b/.github/workflows/python-format.yml @@ -0,0 +1,32 @@ +name: Python formatting with Black and Ruff + +on: + push: + branches: [master] + +jobs: + format: + name: Formatting with Black and Ruff + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Check files using the black formatter + uses: psf/black@stable + id: black + with: + options: "." + continue-on-error: true + + - uses: actions/setup-python@v2 + - name: Install Ruff + run: pip install ruff + + - name: Ruff check and fix + run: | + ruff check . + ruff check --fix . + + - uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: 'Python formatting fixes from Black and Ruff' diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..a015222 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,21 @@ +[tool.black] +line-length = 120 + +[tool.ruff] +line-length = 120 + +[tool.ruff.lint] +select = [ + "F", # pyflakes + "E", # pycodestyle + "W", # pycodestyle + "I", # isort + "N", # pep8-naming + "B", # flake8-ubgbear + "ANN", # flake8-annotations + "Q", # flake8-quotes + "PTH", # flake8-use-pathlib + "UP", # pyupgrade, +] + +[tool.mypy]