Skip to content

Commit 71f966f

Browse files
committed
Python lint: Use ruff instead of flake8
1 parent 44dc320 commit 71f966f

16 files changed

+120
-48
lines changed

.circleci/config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,12 +419,12 @@ jobs:
419419
- run: make -C site text
420420
- run: tools/maint/check_emcc_help_text.py
421421
- run: make -C site html
422-
flake8:
422+
ruff:
423423
executor: bionic
424424
steps:
425425
- checkout
426426
- pip-install
427-
- run: python3 -m flake8 --show-source --statistics
427+
- run: ruff check
428428
mypy:
429429
executor: bionic
430430
steps:
@@ -970,7 +970,7 @@ jobs:
970970
workflows:
971971
build-test:
972972
jobs:
973-
- flake8
973+
- ruff
974974
- mypy
975975
- eslint
976976
- build-docs

.flake8

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

docs/process.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ pre-processor. See [`.clang-format`][clang-format] for more details.
5555
### Python Code
5656

5757
We generally follow the pep8 standard with the major exception that we use 2
58-
spaces for indentation. `flake8` is run on all PRs to ensure that python code
59-
conforms to this style. See [`.flake8`][flake8] for more details.
58+
spaces for indentation. `ruff` is run on all PRs to ensure that Python code
59+
conforms to this style. See [`pyproject.toml`][pyproject.toml] for more details.
6060

6161
#### Static Type Checking
6262

@@ -304,7 +304,7 @@ To update our libraries to a newer musl release:
304304
[emsdk_tags]: https://github.com/emscripten-core/emsdk/tags
305305
[emscripten_tags]: https://github.com/emscripten-core/emscripten/tags
306306
[clang-format]: https://github.com/emscripten-core/emscripten/blob/main/.clang-format
307-
[flake8]: https://github.com/emscripten-core/emscripten/blob/main/.flake8
307+
[pyproject.toml]: https://github.com/emscripten-core/emscripten/blob/main/pyproject.toml
308308
[mypy]: https://github.com/emscripten-core/emscripten/blob/main/.mypy
309309
[update_docs]: https://github.com/emscripten-core/emscripten/blob/main/tools/maint/update_docs.py
310310
[llvm_repo]: https://github.com/llvm/llvm-project

em-config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def main():
2424
not re.match(r"^[\w\W_][\w\W_\d]*$", sys.argv[1]) or \
2525
not hasattr(config, sys.argv[1]):
2626
print('Usage: em-config VAR_NAME', file=sys.stderr)
27-
exit(1)
27+
sys.exit(1)
2828

2929
print(getattr(config, sys.argv[1]))
3030
return 0

emcc.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ def get_clang_command_asm():
10231023
if state.mode == Mode.PCH:
10241024
inputs = [i[1] for i in input_files]
10251025
for header in inputs:
1026-
if not shared.suffix(header) in HEADER_ENDINGS:
1026+
if shared.suffix(header) not in HEADER_ENDINGS:
10271027
exit_with_error(f'cannot mix precompiled headers with non-header inputs: {inputs} : {header}')
10281028
cmd = get_clang_command() + inputs
10291029
if options.output_file:
@@ -1127,7 +1127,13 @@ def version_string():
11271127
return f'emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) {utils.EMSCRIPTEN_VERSION}{revision_suffix}'
11281128

11291129

1130-
def parse_args(newargs):
1130+
def parse_args(newargs): # noqa: C901, PLR0912, PLR0915
1131+
"""Future modifications should consider refactoring to reduce complexity.
1132+
1133+
* The McCabe cyclomatiic complexity is currently 117 vs 10 recommended.
1134+
* There are currently 115 branches vs 12 recommended.
1135+
* There are currently 302 statements vs 50 recommended.
1136+
"""
11311137
options = EmccOptions()
11321138
settings_changes = []
11331139
user_js_defines = []

emrun.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1583,7 +1583,13 @@ def parse_args(args):
15831583
return parser.parse_args(args)
15841584

15851585

1586-
def run(args):
1586+
def run(args): # noqa: C901, PLR0912, PLR0915
1587+
"""Future modifications should consider refactoring to reduce complexity.
1588+
1589+
* The McCabe cyclomatiic complexity is currently 74 vs 10 recommended.
1590+
* There are currently 86 branches vs 12 recommended.
1591+
* There are currently 202 statements vs 50 recommended.
1592+
"""
15871593
global browser_process, browser_exe, processname_killed_atexit, emrun_options, emrun_not_enabled_nag_printed
15881594

15891595
options = emrun_options = parse_args(args)

emsymbolizer.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,8 @@ def parse(self, filename):
121121
self.version = source_map_json['version']
122122
self.sources = source_map_json['sources']
123123

124-
vlq_map = {}
125124
chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
126-
for i, c in enumerate(chars):
127-
vlq_map[c] = i
125+
vlq_map = {c: i for i, c in enumerate(chars)}
128126

129127
def decodeVLQ(string):
130128
result = []

pyproject.toml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,69 @@
1+
[tool.ruff]
2+
exclude = [
3+
"./cache/",
4+
"./node_modules/",
5+
"./site/source/_themes/",
6+
"./site/source/conf.py",
7+
"./system/lib/",
8+
"./test/third_party/",
9+
"./third_party/",
10+
"./tools/filelock.py",
11+
"./tools/scons/",
12+
".git",
13+
]
14+
15+
lint.select = [
16+
"ARG",
17+
"ASYNC",
18+
"B",
19+
"C90",
20+
"E",
21+
"F",
22+
"PERF",
23+
"PL",
24+
"W",
25+
"YTT",
26+
]
27+
28+
lint.ignore = [
29+
"ARG001",
30+
"ARG002",
31+
"ARG005",
32+
"B006",
33+
"B011",
34+
"B018",
35+
"B023",
36+
"B026",
37+
"B904",
38+
"E402",
39+
"E501",
40+
"E721",
41+
"E741",
42+
"PERF203",
43+
"PERF401",
44+
"PLR1704",
45+
"PLR1714",
46+
"PLR5501",
47+
"PLW0602",
48+
"PLW0603",
49+
"PLW2901",
50+
]
51+
52+
lint.per-file-ignores."emrun.py" = [ "PLE0704" ]
53+
54+
lint.mccabe.max-complexity = 48 # Recommended: 10
55+
56+
lint.pylint.allow-magic-value-types = [
57+
"bytes",
58+
"float",
59+
"int",
60+
"str",
61+
]
62+
lint.pylint.max-args = 15 # Recommended: 5
63+
lint.pylint.max-branches = 49 # Recommended: 12
64+
lint.pylint.max-returns = 16 # Recommended: 6
65+
lint.pylint.max-statements = 142 # Recommended: 50
66+
167
[tool.coverage.run]
268
source = [ "." ]
369
omit = [

requirements-dev.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
# TODO(sbc): switch to using Pipenv since it seems like that way to go
22
# these day managing python deps.
3-
# These requirements are only needed for developers who want to run flake8 on
3+
# These requirements are only needed for developers who want to run ruff on
44
# the codebase and generate docs using Sphinx, not for users of emscripten.
55
# Install with `pip3 install -r requirements-dev.txt`
66

7-
flake8==5.0.4
8-
flake8-bugbear==22.9.23
9-
flake8-unused-arguments==0.0.11
107
coverage[toml]==5.5
118
mypy==0.971
9+
ruff==0.8.2
1210
types-requests==2.27.14
1311
unittest-xml-reporting==3.1.0
1412

test/benchmark/benchmark_sse.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,14 @@ def format_comparison(a, b):
134134
total_time_html_scalar = 0
135135
total_time_html_simd = 0
136136

137-
for chart_name in charts_native.keys():
137+
for chart_name, chart_native_results in charts_native.items():
138138
# Extract data for each chart.
139139
categories = []
140140
nativeScalarResults = []
141141
nativeSimdResults = []
142142
htmlScalarResults = []
143143
htmlSimdResults = []
144-
native_results = charts_native[chart_name]
144+
native_results = chart_native_results
145145
wasm_results = charts_html[chart_name]
146146
textual_results_native = '<p>'
147147
textual_results_html = '<p>'

0 commit comments

Comments
 (0)