Skip to content

Commit b7b7ae1

Browse files
authored
Added ruff for pre-commit check (#885)
1 parent 916a7f5 commit b7b7ae1

File tree

3 files changed

+55
-6
lines changed

3 files changed

+55
-6
lines changed

.pre-commit-config.yaml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
repos:
2+
# ruff
3+
- repo: https://github.com/astral-sh/ruff-pre-commit
4+
rev: v0.4.9
5+
hooks:
6+
- id: ruff
7+
types_or: [ python, pyi, jupyter ]
8+
args: [ --fix ]
9+
files: ^ads
10+
exclude: ^docs/
11+
- id: ruff-format
12+
types_or: [ python, pyi, jupyter ]
13+
exclude: ^docs/
214
# Standard hooks
315
- repo: https://github.com/pre-commit/pre-commit-hooks
416
rev: v4.4.0
@@ -20,12 +32,6 @@ repos:
2032
- id: trailing-whitespace
2133
args: [--markdown-linebreak-ext=md]
2234
exclude: ^docs/
23-
# Black, the code formatter, natively supports pre-commit
24-
- repo: https://github.com/psf/black
25-
rev: 23.3.0
26-
hooks:
27-
- id: black
28-
exclude: ^docs/
2935
# Regex based rst files common mistakes detector
3036
- repo: https://github.com/pre-commit/pygrep-hooks
3137
rev: v1.10.0

pyproject.toml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,45 @@ name = "ads" # name for local build and import, see https://flit.pypa.io/en/late
221221
# By default `ads` folder and `LICENSE.txt` file included in sdist. Folders `docs` and `tests` are excluded, as weel as other project files
222222
# Use this section to include/exclude files and folders. See doc: https://flit.pypa.io/en/latest/pyproject_toml.html#sdist-section
223223
include = ["THIRD_PARTY_LICENSES.txt"]
224+
225+
# Configuring Ruff (https://docs.astral.sh/ruff/configuration/)
226+
[tool.ruff]
227+
fix = true
228+
229+
[tool.ruff.lint]
230+
exclude = ["*.yaml", "*jinja2"]
231+
# rules - https://docs.astral.sh/ruff/rules/
232+
extend-ignore = ["E402", "N806", "N803"]
233+
ignore = [
234+
"S101", # use of assert
235+
"B008", # function call in argument defaults
236+
"B017", # pytest.raises considered evil
237+
"B023", # function definition in loop (TODO: un-ignore this)
238+
"B028", # explicit stacklevel for warnings
239+
"C901", # function is too complex (TODO: un-ignore this)
240+
"E501", # from scripts/lint_backend.sh
241+
"PLR091", # complexity rules
242+
"PLR2004", # magic numbers
243+
"PLW2901", # `for` loop variable overwritten by assignment target
244+
"SIM105", # contextlib.suppress (has a performance cost)
245+
"SIM117", # multiple nested with blocks (doesn't look good with gr.Row etc)
246+
"UP006", # use `list` instead of `List` for type annotations (fails for 3.8)
247+
"UP007", # use X | Y for type annotations (TODO: can be enabled once Pydantic plays nice with them)
248+
]
249+
extend-select = [
250+
"ARG",
251+
"B",
252+
"C",
253+
"E",
254+
"F",
255+
"I",
256+
"N",
257+
"PL",
258+
"S101",
259+
"SIM",
260+
"UP",
261+
"W",
262+
]
263+
264+
[tool.ruff.lint.per-file-ignores]
265+
"__init__.py" = ["F401"]

test-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ pytest
99
pytest-cov
1010
pytest-xdist
1111
kubernetes
12+
ruff

0 commit comments

Comments
 (0)