Skip to content

Commit de894d8

Browse files
committed
Add pre-commit CI and ruff in favor of other linters
1 parent 66cf396 commit de894d8

File tree

3 files changed

+97
-46
lines changed

3 files changed

+97
-46
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,10 @@
11
name: CI
2-
32
on:
43
push:
54
branches:
65
- main
76
pull_request:
8-
97
jobs:
10-
11-
lint:
12-
runs-on: ubuntu-latest
13-
strategy:
14-
matrix:
15-
lint-command:
16-
- bandit -r . -x ./tests
17-
- black --check --diff .
18-
- flake8 .
19-
- isort --check-only --diff .
20-
- pydocstyle .
21-
steps:
22-
- uses: actions/checkout@v5
23-
- uses: actions/setup-python@v6
24-
with:
25-
python-version: "3.x"
26-
cache: 'pip'
27-
cache-dependency-path: 'pyproject.toml'
28-
- run: python -m pip install -e .[lint]
29-
- run: ${{ matrix.lint-command }}
30-
318
dist:
329
runs-on: ubuntu-latest
3310
steps:
@@ -43,11 +20,8 @@ jobs:
4320
- uses: actions/upload-artifact@v5
4421
with:
4522
path: dist/*
46-
4723
pytest-os:
4824
name: PyTest
49-
needs:
50-
- lint
5125
strategy:
5226
matrix:
5327
os:
@@ -67,11 +41,8 @@ jobs:
6741
with:
6842
flags: ${{ matrix.os }}
6943
token: ${{ secrets.CODECOV_TOKEN }}
70-
7144
pytest-python:
7245
name: PyTest
73-
needs:
74-
- lint
7546
strategy:
7647
matrix:
7748
python-version:
@@ -80,7 +51,7 @@ jobs:
8051
- "3.12"
8152
- "3.13"
8253
django-version:
83-
- "4.2" # LTS
54+
- "4.2" # LTS
8455
runs-on: ubuntu-latest
8556
steps:
8657
- uses: actions/checkout@v5
@@ -95,11 +66,8 @@ jobs:
9566
with:
9667
flags: py${{ matrix.python-version }}
9768
token: ${{ secrets.CODECOV_TOKEN }}
98-
9969
pytest-django:
10070
name: PyTest
101-
needs:
102-
- lint
10371
strategy:
10472
matrix:
10573
python-version:
@@ -122,11 +90,8 @@ jobs:
12290
with:
12391
flags: dj${{ matrix.django-version }}
12492
token: ${{ secrets.CODECOV_TOKEN }}
125-
12693
pytest-extras:
12794
name: PyTest
128-
needs:
129-
- lint
13095
strategy:
13196
matrix:
13297
extras:
@@ -151,10 +116,9 @@ jobs:
151116
with:
152117
flags: ${{ matrix.extras }}
153118
token: ${{ secrets.CODECOV_TOKEN }}
154-
155119
codeql:
156120
name: CodeQL
157-
needs: [ dist, pytest-os, pytest-python, pytest-django, pytest-extras ]
121+
needs: [dist, pytest-os, pytest-python, pytest-django, pytest-extras]
158122
runs-on: ubuntu-latest
159123
permissions:
160124
actions: read
@@ -163,7 +127,7 @@ jobs:
163127
strategy:
164128
fail-fast: false
165129
matrix:
166-
language: [ python ]
130+
language: [python]
167131
steps:
168132
- name: Checkout
169133
uses: actions/checkout@v5

.pre-commit-config.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v6.0.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: check-merge-conflict
7+
- id: check-ast
8+
- id: check-toml
9+
- id: check-yaml
10+
- id: check-symlinks
11+
- id: debug-statements
12+
- id: end-of-file-fixer
13+
exclude: "pictures/templates/pictures/attrs.html"
14+
- id: no-commit-to-branch
15+
args: [--branch, main]
16+
- repo: https://github.com/asottile/pyupgrade
17+
rev: v3.20.0
18+
hooks:
19+
- id: pyupgrade
20+
- repo: https://github.com/adamchainz/django-upgrade
21+
rev: 1.29.0
22+
hooks:
23+
- id: django-upgrade
24+
- repo: https://github.com/hukkin/mdformat
25+
rev: 0.7.22
26+
hooks:
27+
- id: mdformat
28+
additional_dependencies:
29+
- mdformat-ruff
30+
- mdformat-deflist
31+
- mdformat-footnote
32+
- mdformat-gfm
33+
- mdformat-gfm-alerts
34+
- mdformat-tables
35+
- repo: https://github.com/astral-sh/ruff-pre-commit
36+
rev: v0.13.3
37+
hooks:
38+
- id: ruff-check
39+
args: [--fix, --exit-non-zero-on-fix]
40+
- id: ruff-format
41+
- repo: https://github.com/google/yamlfmt
42+
rev: v0.19.0
43+
hooks:
44+
- id: yamlfmt
45+
ci:
46+
autoupdate_schedule: weekly
47+
skip:
48+
- no-commit-to-branch

pyproject.toml

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,6 @@ test = [
4343
"pytest-django",
4444
"redis",
4545
]
46-
lint = [
47-
"bandit==1.8.6",
48-
"black==25.9.0",
49-
"flake8==7.3.0",
50-
"isort==6.1.0",
51-
"pydocstyle[toml]==6.3.0",
52-
]
5346
dramatiq = [
5447
"django-dramatiq",
5548
]
@@ -102,3 +95,49 @@ skip = ["pictures/_version.py"]
10295

10396
[tool.pydocstyle]
10497
add_ignore = "D1"
98+
99+
[tool.ruff]
100+
src = ["flit_gettext", "tests"]
101+
line-length = 88
102+
indent-width = 4
103+
104+
[tool.ruff.format]
105+
quote-style = "double"
106+
indent-style = "space"
107+
skip-magic-trailing-comma = false
108+
line-ending = "auto"
109+
preview = true
110+
111+
[tool.ruff.lint]
112+
select = [
113+
"D", # pydocstyle
114+
"EXE", # flake8-executable
115+
"F", # pyflakes
116+
"I", # isort
117+
"PT", # flake8-pytest-style
118+
"RET", # flake8-return
119+
"S", # flake8-bandit
120+
"SIM", # flake8-simplify
121+
"UP", # pyupgrade
122+
"W", # pycodestyle warnings
123+
]
124+
125+
ignore = ["D1"]
126+
127+
[tool.ruff.lint.per-file-ignores]
128+
"*/test*.py" = ["S101", "E501", "PT011"]
129+
"*/migrations/*.py" = ["E501"]
130+
131+
[tool.ruff.lint.flake8-pytest-style]
132+
fixture-parentheses = false
133+
mark-parentheses = false
134+
135+
[tool.ruff.lint.isort]
136+
combine-as-imports = true
137+
split-on-trailing-comma = true
138+
section-order = ["future", "standard-library", "third-party", "first-party", "local-folder"]
139+
force-wrap-aliases = true
140+
known-first-party = ["pictures", "tests"]
141+
142+
[tool.ruff.lint.pydocstyle]
143+
convention = "pep257"

0 commit comments

Comments
 (0)