Skip to content

Commit 2e30059

Browse files
committed
Apply automatic Ruff fixes to pull requests
1 parent 3dc8fa4 commit 2e30059

4 files changed

Lines changed: 65 additions & 0 deletions

File tree

‎.github/workflows/autofix.yml‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Ruff rewrites quote styles and capitalises docstrings without any help
2+
# from a person, so a contributor should never have to. This hands those
3+
# fixes to the autofix.ci app, which commits them to the pull request
4+
# branch, forks included. The existing lint gate still reports any
5+
# findings that ruff cannot fix.
6+
#
7+
# The filename and the workflow name are both fixed by autofix.ci, which
8+
# uses them to identify the workflow it trusts. Renaming either one stops
9+
# the app from accepting the patch.
10+
name: autofix.ci # needed to securely identify the workflow
11+
12+
on:
13+
pull_request:
14+
push:
15+
branches: [develop, master]
16+
17+
permissions:
18+
contents: read
19+
20+
concurrency:
21+
group: ${{ github.workflow }}-${{ github.ref }}
22+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
23+
24+
jobs:
25+
autofix:
26+
runs-on: ubuntu-latest
27+
timeout-minutes: 10
28+
steps:
29+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
30+
with:
31+
persist-credentials: false
32+
- uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1
33+
with:
34+
python-version: '3.13'
35+
- run: uvx --with tox-uv tox -e ruff-fix
36+
- uses: autofix-ci/action@c5b2d67aa2274e7b5a18224e8171550871fc7e4a # v1.3.4

‎.github/workflows/main.yml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,13 @@ jobs:
8989
- name: Install dependencies
9090
run: |
9191
python -m pip install --upgrade pip tox
92+
- name: Apply Ruff fixes to pull requests
93+
if: github.event_name == 'pull_request' && matrix.tox-env == 'ruff'
94+
run: tox -e ruff-fix
9295
- name: Test with tox
96+
env:
97+
RUFF_OUTPUT_FORMAT: >-
98+
${{ github.event_name == 'pull_request' && 'github' || 'full' }}
9399
# Step-level continue-on-error keeps the job green for
94100
# experimental (pre-release Python) environments while still
95101
# showing the failing step in the logs

‎CONTRIBUTING.rst‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,15 @@ To run a subset of tests::
161161
$ uv run pytest tests/some_test.py
162162

163163
.. _git-flow-avh: https://github.com/petervanderdoes/gitflow
164+
165+
Automatic formatting
166+
--------------------
167+
168+
Pull requests apply Ruff fixes before the lint check. With the autofix.ci
169+
app installed for this repository, those fixes are committed to the pull
170+
request branch, including forks. Findings Ruff cannot fix still fail CI.
171+
Push builds check the committed files without applying fixes.
172+
173+
Apply the same fixes locally with::
174+
175+
uvx --with tox-uv tox -e ruff-fix

‎tox.ini‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ commands =
8282
sphinx-build -b linkcheck -d docs/_build/doctrees docs docs/_build/linkcheck
8383

8484
[testenv:ruff]
85+
pass_env = RUFF_OUTPUT_FORMAT
8586
commands =
8687
ruff check
8788
ruff format --check
@@ -93,3 +94,13 @@ changedir = {toxinidir}
9394
commands = codespell .
9495
deps = codespell
9596
skip_install = true
97+
98+
99+
[testenv:ruff-fix]
100+
labels = fix
101+
description = Apply the available Ruff fixes
102+
commands =
103+
ruff check --fix --exit-zero
104+
ruff format
105+
deps = ruff
106+
skip_install = true

0 commit comments

Comments
 (0)