Skip to content

Commit 6ea061d

Browse files
committed
chore: Replace Black, isort, and flake8 with Ruff
Consolidate Python linting and formatting tools into Ruff for faster execution and simpler configuration: - Add ruff.toml with comprehensive lint rules (E, W, F, I, N, UP, B, C4, SIM, RUF, TCH, PTH, TID, ASYNC) - Update .pre-commit-config.yaml to use ruff and ruff-format hooks - Remove autoflake, isort, and black hooks - Add additional pre-commit checks (large files, json, toml, merge conflicts, debug statements) - Add .ruff_cache/ to .gitignore
1 parent 6bdb5d8 commit 6ea061d

File tree

3 files changed

+127
-23
lines changed

3 files changed

+127
-23
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ build/
1111
*.key
1212
.cache
1313
.vscode/
14+
15+
# Ruff
16+
.ruff_cache/

.pre-commit-config.yaml

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,29 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.6.0
3+
rev: v5.0.0
44
hooks:
55
- id: check-yaml
66
- id: end-of-file-fixer
77
exclude: '^src/frontend/dist/|\.svg$|\.png$|\.jpg$|\.jpeg$|\.gif$|\.webp$'
88
- id: trailing-whitespace
99
- id: mixed-line-ending
1010
args: ['--fix=lf']
11+
- id: check-added-large-files
12+
args: ['--maxkb=1000']
13+
- id: check-json
14+
exclude: '^src/frontend/.*\.json$' # tsconfig uses JSON5 (comments, trailing commas)
15+
- id: check-toml
16+
- id: check-merge-conflict
17+
- id: debug-statements
1118

12-
- repo: https://github.com/PyCQA/autoflake
13-
rev: v2.3.1
19+
# Ruff replaces autoflake, isort, black, and many flake8 plugins
20+
- repo: https://github.com/astral-sh/ruff-pre-commit
21+
rev: v0.14.6
1422
hooks:
15-
- id: autoflake
16-
args:
17-
- --remove-all-unused-imports
18-
- --remove-unused-variables
19-
- --in-place
20-
21-
- repo: https://github.com/pycqa/isort
22-
rev: 5.13.2
23-
hooks:
24-
- id: isort
25-
language_version: python3.11
26-
args: ["--profile", "black"]
27-
exclude: '^src/parallax/p2p/proto/forward_pb2\.py$'
28-
29-
- repo: https://github.com/psf/black
30-
rev: 24.3.0
31-
hooks:
32-
- id: black
33-
language_version: python3.11
34-
exclude: '^src/parallax/p2p/proto/forward_pb2\.py$'
23+
# Run the linter
24+
- id: ruff
25+
args: [--fix]
26+
exclude: '^src/parallax/p2p/proto/'
27+
# Run the formatter
28+
- id: ruff-format
29+
exclude: '^src/parallax/p2p/proto/'

ruff.toml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Ruff configuration
2+
# https://docs.astral.sh/ruff/
3+
4+
line-length = 100
5+
target-version = "py312"
6+
7+
# Exclude generated files and caches
8+
exclude = [
9+
".git",
10+
".venv",
11+
"__pycache__",
12+
"build",
13+
"dist",
14+
"*.egg-info",
15+
"src/parallax/p2p/proto", # Generated protobuf
16+
"src/frontend/dist",
17+
"src/frontend/node_modules",
18+
]
19+
20+
[lint]
21+
# Enable pycodestyle (E, W), Pyflakes (F), isort (I), and more
22+
select = [
23+
"E", # pycodestyle errors
24+
"W", # pycodestyle warnings
25+
"F", # Pyflakes
26+
"I", # isort
27+
"N", # pep8-naming
28+
"UP", # pyupgrade
29+
"B", # flake8-bugbear
30+
"C4", # flake8-comprehensions
31+
"SIM", # flake8-simplify
32+
"RUF", # Ruff-specific rules
33+
"TCH", # flake8-type-checking
34+
"PTH", # flake8-use-pathlib
35+
"TID", # flake8-tidy-imports
36+
"ASYNC", # flake8-async
37+
]
38+
39+
# Allow autofix for all enabled rules
40+
fixable = ["ALL"]
41+
unfixable = []
42+
43+
# Ignore specific rules
44+
ignore = [
45+
"E501", # Line too long (handled by formatter)
46+
"B008", # Do not perform function calls in argument defaults
47+
"C901", # Function is too complex
48+
"SIM108", # Use ternary operator (sometimes less readable)
49+
]
50+
51+
# Deferred rules - require code changes, to be addressed in follow-up PRs
52+
# TODO: Remove from extend-ignore as issues are fixed
53+
extend-ignore = [
54+
# === Require refactoring ===
55+
"PTH", # pathlib migration - significant refactor
56+
"TCH", # TYPE_CHECKING imports - requires careful review
57+
"UP035", # typing.List -> list - touches many files
58+
"B006", # mutable-argument-default - needs case-by-case review
59+
"B023", # function-uses-loop-variable - needs case-by-case review
60+
"E402", # module-import-not-at-top - sometimes intentional for side effects
61+
62+
# === Stylistic - sometimes the "violation" is clearer ===
63+
"SIM102", # nested if statements
64+
"SIM105", # suppressible exception (contextlib.suppress)
65+
"SIM115", # open-file-with-context-handler
66+
"SIM117", # nested with statements
67+
"SIM118", # key in dict.keys() -> key in dict
68+
"E731", # lambda assignment
69+
70+
# === Naming - often intentional (math notation, DSL) ===
71+
"N806", # non-lowercase variable in function
72+
"N803", # invalid argument name
73+
"N802", # invalid function name
74+
"E741", # ambiguous variable name (l, O, I)
75+
76+
# === Low priority / noisy ===
77+
"RUF059", # unused unpacked variable
78+
"RUF013", # implicit-optional (None default without Optional type)
79+
"RUF002", # ambiguous unicode in docstring
80+
"RUF003", # ambiguous unicode in comment
81+
"RUF012", # mutable class default (needs ClassVar annotation)
82+
"B018", # useless expression - sometimes intentional for side effects
83+
"B904", # raise-without-from - needs case-by-case review
84+
"ASYNC109", # async timeout parameter - needs careful review
85+
]
86+
87+
[lint.per-file-ignores]
88+
# Ignore imports in __init__.py files
89+
"__init__.py" = ["F401", "F403"]
90+
# Test files can have additional imports
91+
"tests/**/*.py" = ["F401", "F403", "B018"]
92+
# Benchmark code has known issues to be fixed separately
93+
"src/backend/benchmark/**/*.py" = ["F821", "C419"]
94+
95+
[lint.isort]
96+
known-first-party = ["parallax", "scheduling", "parallax_utils", "backend"]
97+
combine-as-imports = true
98+
lines-after-imports = 2
99+
100+
[format]
101+
# Use double quotes for strings
102+
quote-style = "double"
103+
indent-style = "space"
104+
skip-magic-trailing-comma = false
105+
line-ending = "auto"
106+
docstring-code-format = true

0 commit comments

Comments
 (0)