Skip to content

Commit 5ba5da2

Browse files
committed
Apply automatic Ruff fixes to pull requests
1 parent d7eba12 commit 5ba5da2

4 files changed

Lines changed: 67 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/ci.yml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,13 @@ jobs:
4545
- uses: astral-sh/setup-uv@v8.2.0
4646
with:
4747
cache-suffix: lint
48+
- name: Apply Ruff fixes to pull requests
49+
if: github.event_name == 'pull_request'
50+
run: uvx --with tox-uv tox -e ruff-fix
4851
- run: uvx --with tox-uv tox -e lint
52+
env:
53+
RUFF_OUTPUT_FORMAT: >-
54+
${{ github.event_name == 'pull_request' && 'github' || 'full' }}
4955
5056
type-check:
5157
runs-on: ubuntu-latest

‎CONTRIBUTING.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,16 @@ Lastly we test the types using `pyright`:
8585
```bash
8686
$ pyright
8787
```
88+
89+
## Automatic formatting
90+
91+
Pull requests apply Ruff fixes before the lint check. With the autofix.ci
92+
app installed for this repository, those fixes are committed to the pull
93+
request branch, including forks. Findings Ruff cannot fix still fail CI.
94+
Push builds check the committed files without applying fixes.
95+
96+
Apply the same fixes locally with:
97+
98+
```console
99+
uvx --with tox-uv tox -e ruff-fix
100+
```

‎tox.ini‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ pass_env = COVERAGE_FILE
4646
commands = pytest --cov-fail-under=0 {posargs}
4747

4848
[testenv:lint]
49+
pass_env = RUFF_OUTPUT_FORMAT
4950
runner = uv-venv-runner
5051
dependency_groups = dev
5152
commands =
@@ -85,3 +86,14 @@ uv_sync_locked = false
8586
commands =
8687
coverage erase
8788
pytest --cov=python_utils --cov-report=term-missing --cov-fail-under=100
89+
90+
91+
[testenv:ruff-fix]
92+
labels = fix
93+
description = Apply the available Ruff fixes
94+
skip_install = true
95+
runner = uv-venv-runner
96+
dependency_groups = dev
97+
commands =
98+
ruff check --fix --exit-zero .
99+
ruff format .

0 commit comments

Comments
 (0)