Skip to content

Commit

Permalink
build: replace Python linter flake8 with ruff
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
cclauss authored and targos committed May 2, 2023
1 parent 7ca416a commit 78c0824
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 14 deletions.
3 changes: 0 additions & 3 deletions .flake8

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ jobs:
run: npx envinfo
- name: Lint Python
run: |
make lint-py-build || true
make lint-py-build
make lint-py
lint-yaml:
if: github.event.pull_request.draft == false
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
!.eslintignore
!.eslintrc.js
!.eslintrc.yaml
!.flake8
!.gitattributes
!.github
!.gitignore
Expand Down
18 changes: 9 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1489,22 +1489,22 @@ cpplint: lint-cpp
$(warning Please use lint-cpp instead of cpplint)

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

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

Expand Down
48 changes: 48 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[tool.ruff]
select = [
"C90", # McCabe cyclomatic complexity
"E", # pycodestyle
"F", # Pyflakes
"ICN", # flake8-import-conventions
"INT", # flake8-gettext
"PLC", # Pylint conventions
"PLE", # Pylint errors
"PLR09", # Pylint refactoring: max-args, max-branches, max returns, max-statements
"PYI", # flake8-pyi
"RSE", # flake8-raise
"RUF", # Ruff-specific rules
"T10", # flake8-debugger
"TCH", # flake8-type-checking
"TID", # flake8-tidy-imports
"W", # pycodestyle
"YTT", # flake8-2020
]
exclude = [
"deps",
"tools/inspector_protocol",
]
ignore = [
"E401",
"E402",
"E7",
"PLC1901",
"RUF005",
"RUF100",
]
line-length = 172
target-version = "py37"

[tool.ruff.mccabe]
max-complexity = 100

[tool.ruff.per-file-ignores]
"tools/checkimports.py" = ["W605"]
"tools/gyp/pylib/gyp/xcodeproj_file.py" = ["PLE0101"]
"tools/icu/shrink-icu-src.py" = ["W605"]
"tools/mkssldef.py" = ["W605"]

[tool.ruff.pylint]
max-args = 12
max-branches = 110
max-returns = 12
max-statements = 289

0 comments on commit 78c0824

Please sign in to comment.