Skip to content

Commit 78c0824

Browse files
cclausstargos
authored andcommitted
build: replace Python linter flake8 with ruff
PR-URL: #47519 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Jiawen Geng <[email protected]>
1 parent 7ca416a commit 78c0824

File tree

5 files changed

+58
-14
lines changed

5 files changed

+58
-14
lines changed

Diff for: .flake8

-3
This file was deleted.

Diff for: .github/workflows/linters.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ jobs:
129129
run: npx envinfo
130130
- name: Lint Python
131131
run: |
132-
make lint-py-build || true
132+
make lint-py-build
133133
make lint-py
134134
lint-yaml:
135135
if: github.event.pull_request.draft == false

Diff for: .gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
!.eslintignore
1515
!.eslintrc.js
1616
!.eslintrc.yaml
17-
!.flake8
1817
!.gitattributes
1918
!.github
2019
!.gitignore

Diff for: Makefile

+9-9
Original file line numberDiff line numberDiff line change
@@ -1489,22 +1489,22 @@ cpplint: lint-cpp
14891489
$(warning Please use lint-cpp instead of cpplint)
14901490

14911491
.PHONY: lint-py-build
1492-
# python -m pip install flake8
1492+
# python -m pip install ruff
14931493
# Try with '--system' if it fails without; the system may have set '--user'
14941494
lint-py-build:
1495-
$(info Pip installing flake8 linter on $(shell $(PYTHON) --version)...)
1496-
$(PYTHON) -m pip install --upgrade -t tools/pip/site-packages flake8 || \
1497-
$(PYTHON) -m pip install --upgrade --system -t tools/pip/site-packages flake8
1495+
$(info Pip installing ruff on $(shell $(PYTHON) --version)...)
1496+
$(PYTHON) -m pip install --upgrade --target tools/pip/site-packages ruff || \
1497+
$(PYTHON) -m pip install --upgrade --system --target tools/pip/site-packages ruff
14981498

14991499
.PHONY: lint-py
1500-
ifneq ("","$(wildcard tools/pip/site-packages/flake8)")
1501-
# Lints the Python code with flake8.
1502-
# Flag the build if there are Python syntax errors or undefined names
1500+
ifneq ("","$(wildcard tools/pip/site-packages/ruff)")
1501+
# Lint the Python code with ruff.
15031502
lint-py:
1504-
PYTHONPATH=tools/pip $(PYTHON) -m flake8 --count --show-source --statistics .
1503+
tools/pip/site-packages/bin/ruff --version
1504+
tools/pip/site-packages/bin/ruff .
15051505
else
15061506
lint-py:
1507-
$(warning Python linting with flake8 is not available)
1507+
$(warning Python linting with ruff is not available)
15081508
$(warning Run 'make lint-py-build')
15091509
endif
15101510

Diff for: pyproject.toml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
[tool.ruff]
2+
select = [
3+
"C90", # McCabe cyclomatic complexity
4+
"E", # pycodestyle
5+
"F", # Pyflakes
6+
"ICN", # flake8-import-conventions
7+
"INT", # flake8-gettext
8+
"PLC", # Pylint conventions
9+
"PLE", # Pylint errors
10+
"PLR09", # Pylint refactoring: max-args, max-branches, max returns, max-statements
11+
"PYI", # flake8-pyi
12+
"RSE", # flake8-raise
13+
"RUF", # Ruff-specific rules
14+
"T10", # flake8-debugger
15+
"TCH", # flake8-type-checking
16+
"TID", # flake8-tidy-imports
17+
"W", # pycodestyle
18+
"YTT", # flake8-2020
19+
]
20+
exclude = [
21+
"deps",
22+
"tools/inspector_protocol",
23+
]
24+
ignore = [
25+
"E401",
26+
"E402",
27+
"E7",
28+
"PLC1901",
29+
"RUF005",
30+
"RUF100",
31+
]
32+
line-length = 172
33+
target-version = "py37"
34+
35+
[tool.ruff.mccabe]
36+
max-complexity = 100
37+
38+
[tool.ruff.per-file-ignores]
39+
"tools/checkimports.py" = ["W605"]
40+
"tools/gyp/pylib/gyp/xcodeproj_file.py" = ["PLE0101"]
41+
"tools/icu/shrink-icu-src.py" = ["W605"]
42+
"tools/mkssldef.py" = ["W605"]
43+
44+
[tool.ruff.pylint]
45+
max-args = 12
46+
max-branches = 110
47+
max-returns = 12
48+
max-statements = 289

0 commit comments

Comments
 (0)