Skip to content

Commit 9da5ea6

Browse files
committed
build: replace Python linter flake8 with ruff
1 parent 56ccd59 commit 9da5ea6

File tree

15 files changed

+65
-36
lines changed

15 files changed

+65
-36
lines changed

.flake8

Lines changed: 0 additions & 3 deletions
This file was deleted.

.gitignore

Lines changed: 0 additions & 1 deletion
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

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,24 +1489,16 @@ 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 linter on $(shell $(PYTHON) --version)...)
1496+
$(PYTHON) -m pip install --upgrade --user ruff
14981497

14991498
.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
1499+
# Lints the Python code with ruff.
15031500
lint-py:
1504-
PYTHONPATH=tools/pip $(PYTHON) -m flake8 --count --show-source --statistics .
1505-
else
1506-
lint-py:
1507-
$(warning Python linting with flake8 is not available)
1508-
$(warning Run 'make lint-py-build')
1509-
endif
1501+
ruff .
15101502

15111503
.PHONY: lint-yaml-build
15121504
# python -m pip install yamllint

pyproject.toml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
]
31+
line-length = 172
32+
target-version = "py37"
33+
34+
[tool.ruff.mccabe]
35+
max-complexity = 100
36+
37+
[tool.ruff.pylint]
38+
max-args = 12
39+
max-branches = 110
40+
max-returns = 12
41+
max-statements = 289

tools/checkimports.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import itertools
99

1010
def do_exist(file_name, lines, imported):
11-
if not any(not re.match('using \w+::{0};'.format(imported), line) and
11+
if not any(not re.match('using \\w+::{0};'.format(imported), line) and
1212
re.search('\\b{0}\\b'.format(imported), line) for line in lines):
1313
print('File "{0}" does not use "{1}"'.format(file_name, imported))
1414
return False

tools/gyp/.github/workflows/Python_tests.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ jobs:
1111
max-parallel: 8
1212
matrix:
1313
os: [macos-latest, ubuntu-latest] # , windows-latest]
14-
python-version: ["3.7", "3.8", "3.9", "3.10"]
14+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
1515
steps:
1616
- uses: actions/checkout@v3
1717
- name: Set up Python ${{ matrix.python-version }}
18-
uses: actions/setup-python@v3
18+
uses: actions/setup-python@v4
1919
with:
2020
python-version: ${{ matrix.python-version }}
2121
- name: Install dependencies
2222
run: |
2323
python -m pip install --upgrade pip
2424
pip install -r requirements_dev.txt
25-
- name: Lint with flake8
26-
run: flake8 . --ignore=E203,W503 --max-complexity=101 --max-line-length=88 --show-source --statistics
25+
- name: Lint with ruff
26+
run: ruff --format=github .
2727
- name: Test with pytest
2828
run: pytest
2929
# - name: Run doctests with pytest

tools/gyp/gyp_main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def UnixifyPath(path):
3939
# else the 'gyp' library will not be found
4040
path = UnixifyPath(sys.argv[0])
4141
sys.path.insert(0, os.path.join(os.path.dirname(path), "pylib"))
42-
import gyp # noqa: E402
42+
import gyp
4343

4444
if __name__ == "__main__":
4545
sys.exit(gyp.script_main())

tools/gyp/pylib/gyp/generator/make.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def CalculateGeneratorInputInfo(params):
216216
217217
quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@
218218
cmd_solink_module = $(LINK.$(TOOLSET)) -bundle $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(filter-out FORCE_DO_CMD, $^) $(LIBS)
219-
""" # noqa: E501
219+
"""
220220

221221
LINK_COMMANDS_ANDROID = """\
222222
quiet_cmd_alink = AR($(TOOLSET)) $@
@@ -286,7 +286,7 @@ def CalculateGeneratorInputInfo(params):
286286
287287
quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@
288288
cmd_solink_module = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(filter-out FORCE_DO_CMD, $^) $(LIBS)
289-
""" # noqa: E501
289+
"""
290290

291291

292292
LINK_COMMANDS_OS400 = """\
@@ -304,7 +304,7 @@ def CalculateGeneratorInputInfo(params):
304304
305305
quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@
306306
cmd_solink_module = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(filter-out FORCE_DO_CMD, $^) $(LIBS)
307-
""" # noqa: E501
307+
"""
308308

309309

310310
LINK_COMMANDS_OS390 = """\
@@ -474,7 +474,7 @@ def CalculateGeneratorInputInfo(params):
474474
cmd_symlink = ln -sf "$<" "$@"
475475
476476
%(link_commands)s
477-
""" # noqa: E501
477+
"""
478478
r"""
479479
# Define an escape_quotes function to escape single quotes.
480480
# This allows us to handle quotes properly as long as we always use
@@ -573,7 +573,7 @@ def CalculateGeneratorInputInfo(params):
573573
.PHONY: FORCE_DO_CMD
574574
FORCE_DO_CMD:
575575
576-
""" # noqa: E501
576+
"""
577577
)
578578

579579
SHARED_HEADER_MAC_COMMANDS = """
@@ -604,7 +604,7 @@ def CalculateGeneratorInputInfo(params):
604604
605605
quiet_cmd_infoplist = INFOPLIST $@
606606
cmd_infoplist = $(CC.$(TOOLSET)) -E -P -Wno-trigraphs -x c $(INFOPLIST_DEFINES) "$<" -o "$@"
607-
""" # noqa: E501
607+
"""
608608

609609

610610
def WriteRootHeaderSuffixRules(writer):

tools/gyp/pylib/gyp/generator/msvs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ def _EscapeEnvironmentVariableExpansion(s):
756756
757757
Returns:
758758
The escaped string.
759-
""" # noqa: E731,E123,E501
759+
"""
760760
s = s.replace("%", "%%")
761761
return s
762762

tools/gyp/pylib/gyp/generator/ninja.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2533,7 +2533,7 @@ def GenerateOutputForConfig(target_list, target_dicts, data, params, config_name
25332533
description="SOLINK $lib",
25342534
restat=True,
25352535
command=mtime_preserving_solink_base
2536-
% {"suffix": "@$link_file_list"}, # noqa: E501
2536+
% {"suffix": "@$link_file_list"},
25372537
rspfile="$link_file_list",
25382538
rspfile_content=(
25392539
"-Wl,--whole-archive $in $solibs -Wl," "--no-whole-archive $libs"

tools/gyp/pylib/gyp/xcode_emulation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1733,7 +1733,7 @@ def _GetXcodeEnv(
17331733
"CONFIGURATION": configuration,
17341734
"PRODUCT_NAME": xcode_settings.GetProductName(),
17351735
# For FULL_PRODUCT_NAME see:
1736-
# /Developer/Platforms/MacOSX.platform/Developer/Library/Xcode/Specifications/MacOSX\ Product\ Types.xcspec # noqa: E501
1736+
# /Developer/Platforms/MacOSX.platform/Developer/Library/Xcode/Specifications/MacOSX\ Product\ Types.xcspec
17371737
"SRCROOT": srcroot,
17381738
"SOURCE_ROOT": "${SRCROOT}",
17391739
# This is not true for static libraries, but currently the env is only

tools/gyp/pylib/gyp/xcodeproj_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2770,7 +2770,7 @@ def __init__(self, properties=None, id=None, parent=None, path=None):
27702770
self.path = path
27712771
self._other_pbxprojects = {}
27722772
# super
2773-
return XCContainerPortal.__init__(self, properties, id, parent)
2773+
XCContainerPortal.__init__(self, properties, id, parent)
27742774

27752775
def Name(self):
27762776
name = self.path

tools/gyp/requirements_dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
flake8
21
pytest
2+
ruff

tools/icu/shrink-icu-src.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def print_size(fn):
4848
size = (os.stat(fn).st_size) / 1024000
4949
print('%dM\t%s' % (size, fn))
5050

51-
ignore_regex = re.compile('^.*\.(vcxproj|filters|nrm|icu|dat|xml|txt|ac|guess|m4|in|sub|py|mak)$')
51+
ignore_regex = re.compile('^.*\\.(vcxproj|filters|nrm|icu|dat|xml|txt|ac|guess|m4|in|sub|py|mak)$')
5252

5353
def icu_ignore(dir, files):
5454
subdir = dir[len(options.icusrc)+1::]

tools/mkssldef.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
for filename in filenames:
2828
for line in open(filename).readlines():
29-
name, _, _, meta, _ = re.split('\s+', line)
29+
name, _, _, meta, _ = re.split('\\s+', line)
3030
if any(p.match(name) for p in excludes): continue
3131
meta = meta.split(':')
3232
assert meta[0] in ('EXIST', 'NOEXIST')

0 commit comments

Comments
 (0)