Skip to content

Commit 48468c4

Browse files
cclaussMoLow
authored andcommitted
build: replace Python linter flake8 with ruff
PR-URL: #47519 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
1 parent d40bcdd commit 48468c4

File tree

5 files changed

+58
-14
lines changed

5 files changed

+58
-14
lines changed

.flake8

-3
This file was deleted.

.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

.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

Makefile

+9-9
Original file line numberDiff line numberDiff line change
@@ -1514,22 +1514,22 @@ cpplint: lint-cpp
15141514
$(warning Please use lint-cpp instead of cpplint)
15151515

15161516
.PHONY: lint-py-build
1517-
# python -m pip install flake8
1517+
# python -m pip install ruff
15181518
# Try with '--system' if it fails without; the system may have set '--user'
15191519
lint-py-build:
1520-
$(info Pip installing flake8 linter on $(shell $(PYTHON) --version)...)
1521-
$(PYTHON) -m pip install --upgrade -t tools/pip/site-packages flake8 || \
1522-
$(PYTHON) -m pip install --upgrade --system -t tools/pip/site-packages flake8
1520+
$(info Pip installing ruff on $(shell $(PYTHON) --version)...)
1521+
$(PYTHON) -m pip install --upgrade --target tools/pip/site-packages ruff || \
1522+
$(PYTHON) -m pip install --upgrade --system --target tools/pip/site-packages ruff
15231523

15241524
.PHONY: lint-py
1525-
ifneq ("","$(wildcard tools/pip/site-packages/flake8)")
1526-
# Lints the Python code with flake8.
1527-
# Flag the build if there are Python syntax errors or undefined names
1525+
ifneq ("","$(wildcard tools/pip/site-packages/ruff)")
1526+
# Lint the Python code with ruff.
15281527
lint-py:
1529-
PYTHONPATH=tools/pip $(PYTHON) -m flake8 --count --show-source --statistics .
1528+
tools/pip/site-packages/bin/ruff --version
1529+
tools/pip/site-packages/bin/ruff .
15301530
else
15311531
lint-py:
1532-
$(warning Python linting with flake8 is not available)
1532+
$(warning Python linting with ruff is not available)
15331533
$(warning Run 'make lint-py-build')
15341534
endif
15351535

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)