Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: replace Python linter flake8 with ruff #47519

Merged
merged 3 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
]
richardlau marked this conversation as resolved.
Show resolved Hide resolved
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