Skip to content

Commit 24e4d6e

Browse files
authored
Upgrade to ruff v0.9.1 and add PIE ruff rules. NFC (#23362)
Upgrade to ruff v0.9.1 with 2025 stable format. Required no code changes. https://github.com/astral-sh/ruff/releases Fix #23085 (comment) Add https://docs.astral.sh/ruff/rules/#flake8-pie-pie Add [`ruff rule PLR1714`](https://docs.astral.sh/ruff/rules/repeated-equality-comparison)
1 parent d1efd6c commit 24e4d6e

21 files changed

+33
-38
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,8 @@ jobs:
425425
- checkout
426426
- pip-install
427427
- run: ruff check
428-
# TODO (cclauss): When ruff supports rule E303 without --preview, remove following line
429-
- run: ruff check --preview --select=E303
428+
# TODO (cclauss): When ruff supports rules E20,E30 without --preview, remove following line
429+
- run: ruff check --preview --select=E20,E30
430430
mypy:
431431
executor: focal
432432
steps:

emcc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ def run(args):
644644
print(compiler_rt.get_path(absolute=True))
645645
return 0
646646

647-
print_file_name = [a for a in newargs if a.startswith('-print-file-name=') or a.startswith('--print-file-name=')]
647+
print_file_name = [a for a in newargs if a.startswith(('-print-file-name=', '--print-file-name='))]
648648
if print_file_name:
649649
libname = print_file_name[-1].split('=')[1]
650650
system_libpath = cache.get_lib_dir(absolute=True)
@@ -1541,7 +1541,7 @@ def parse_value(text, expected_type):
15411541
# places here.
15421542
def parse_string_value(text):
15431543
first = text[0]
1544-
if first == "'" or first == '"':
1544+
if first in {"'", '"'}:
15451545
text = text.rstrip()
15461546
if text[-1] != text[0] or len(text) < 2:
15471547
raise ValueError(f'unclosed quoted string. expected final character to be "{text[0]}" and length to be greater than 1 in "{text[0]}"')
@@ -1558,7 +1558,7 @@ def parse_string_list_members(text):
15581558
if not len(current):
15591559
raise ValueError('empty value in string list')
15601560
first = current[0]
1561-
if not (first == "'" or first == '"'):
1561+
if first not in {"'", '"'}:
15621562
result.append(current.rstrip())
15631563
else:
15641564
start = index

emrun.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ def find_gpu_model(model):
817817
return gpu
818818
return None
819819

820-
for i in range(0, 16):
820+
for i in range(16):
821821
try:
822822
hHardwareReg = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, 'HARDWARE')
823823
hDeviceMapReg = winreg.OpenKey(hHardwareReg, 'DEVICEMAP')
@@ -1398,7 +1398,7 @@ def get_system_info(format_json):
13981398
if len(gpus) == 1:
13991399
info += 'GPU: ' + gpus[0]['model'] + ' with ' + str(gpus[0]['ram'] // 1024 // 1024) + " MB of VRAM\n"
14001400
elif len(gpus) > 1:
1401-
for i in range(0, len(gpus)):
1401+
for i in range(len(gpus)):
14021402
info += 'GPU' + str(i) + ": " + gpus[i]['model'] + ' with ' + str(gpus[i]['ram'] // 1024 // 1024) + ' MBs of VRAM\n'
14031403
info += 'UUID: ' + unique_system_id
14041404
return info.strip()
@@ -1427,7 +1427,6 @@ def list_processes_by_name(exe_full_path):
14271427
except Exception:
14281428
# Fail gracefully if psutil not available
14291429
logv('import psutil failed, unable to detect browser processes')
1430-
pass
14311430

14321431
logv('Searching for processes by full path name "' + exe_full_path + '".. found ' + str(len(pids)) + ' entries')
14331432

@@ -1637,15 +1636,15 @@ def run(args): # noqa: C901, PLR0912, PLR0915
16371636
file_to_serve = options.serve
16381637
else:
16391638
file_to_serve = '.'
1640-
file_to_serve_is_url = file_to_serve.startswith('file://') or file_to_serve.startswith('http://') or file_to_serve.startswith('https://')
1639+
file_to_serve_is_url = file_to_serve.startswith(('file://', 'http://', 'https://'))
16411640

16421641
if options.serve_root:
16431642
serve_dir = os.path.abspath(options.serve_root)
16441643
else:
16451644
if file_to_serve == '.' or file_to_serve_is_url:
16461645
serve_dir = os.path.abspath('.')
16471646
else:
1648-
if file_to_serve.endswith('/') or file_to_serve.endswith('\\') or os.path.isdir(file_to_serve):
1647+
if file_to_serve.endswith(('/', '\\')) or os.path.isdir(file_to_serve):
16491648
serve_dir = file_to_serve
16501649
else:
16511650
serve_dir = os.path.dirname(os.path.abspath(file_to_serve))
@@ -1684,7 +1683,7 @@ def run(args): # noqa: C901, PLR0912, PLR0915
16841683
return 1
16851684
elif options.browser == 'firefox':
16861685
browser_app = 'org.mozilla.firefox/org.mozilla.gecko.BrowserApp'
1687-
elif options.browser == 'firefox_nightly' or options.browser == 'fenix':
1686+
elif options.browser in {'firefox_nightly', 'fenix'}:
16881687
browser_app = 'org.mozilla.fenix/org.mozilla.gecko.BrowserApp'
16891688
elif options.browser == 'chrome':
16901689
browser_app = 'com.android.chrome/com.google.android.apps.chrome.Main'

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ lint.select = [
2020
"E",
2121
"F",
2222
"PERF",
23+
"PIE",
2324
"PL",
2425
"W",
2526
"YTT",
@@ -42,7 +43,6 @@ lint.ignore = [
4243
"PERF203",
4344
"PERF401",
4445
"PLR1704",
45-
"PLR1714",
4646
"PLR5501",
4747
"PLW0602",
4848
"PLW0603",

requirements-dev.txt

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

77
coverage[toml]==5.5
88
mypy==0.971
9-
ruff==0.8.2
9+
ruff==0.9.1
1010
types-requests==2.27.14
1111
unittest-xml-reporting==3.1.0
1212

test/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ def with_all_eh_sjlj(f):
637637
def metafunc(self, mode, *args, **kwargs):
638638
if DEBUG:
639639
print('parameterize:eh_mode=%s' % mode)
640-
if mode == 'wasm' or mode == 'wasm_exnref':
640+
if mode in {'wasm', 'wasm_exnref'}:
641641
# Wasm EH is currently supported only in wasm backend and V8
642642
if self.is_wasm2js():
643643
self.skipTest('wasm2js does not support wasm EH/SjLj')
@@ -674,7 +674,7 @@ def with_all_sjlj(f):
674674

675675
@wraps(f)
676676
def metafunc(self, mode, *args, **kwargs):
677-
if mode == 'wasm' or mode == 'wasm_exnref':
677+
if mode in {'wasm', 'wasm_exnref'}:
678678
if self.is_wasm2js():
679679
self.skipTest('wasm2js does not support wasm SjLj')
680680
# FIXME Temporarily disabled. Enable this later when the bug is fixed.

test/gen_large_switchcase.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
cases = ''
1111
i = 1
1212
incr = 1
13-
for _ in range(0, num_cases):
13+
for _ in range(num_cases):
1414
cases += ' case ' + str(i) + ': return "' + str(i) + str(i) + str(i) + '";\n'
1515
i += incr
1616
incr = (incr % 5) + 1

test/runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ def flattened_tests(loaded_tests):
314314
tests.extend(subsuite)
315315
return tests
316316

317+
317318
def suite_for_module(module, tests):
318319
suite_supported = module.__name__ in ('test_core', 'test_other', 'test_posixtest')
319320
if not common.EMTEST_SAVE_DIR and not shared.DEBUG:

test/test_browser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def reftest(self, filename, reference, reference_slack=0, *args, **kwargs):
284284
"""
285285
reference = find_browser_test_file(reference)
286286
assert 'expected' not in kwargs
287-
expected = [str(i) for i in range(0, reference_slack + 1)]
287+
expected = [str(i) for i in range(reference_slack + 1)]
288288
self.make_reftest(reference)
289289
if '--proxy-to-worker' in self.emcc_args:
290290
assert 'post_build' not in kwargs

test/test_other.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,7 @@ def verify_includes(stderr):
11521152
i = os.path.normpath(i)
11531153
# we also allow for the cache include directory and llvm's own builtin includes.
11541154
# all other include paths should be inside the sysroot.
1155-
if i.startswith(cachedir) or i.startswith(llvmroot):
1155+
if i.startswith((cachedir, llvmroot)):
11561156
continue
11571157
self.assertContained(path_from_root('system'), i)
11581158

@@ -11374,7 +11374,7 @@ def print_percent(actual, expected):
1137411374
obtained_results[f] = size
1137511375
obtained_results[f_gz] = size_gz
1137611376

11377-
if size != expected_size and (f.endswith('.js') or f.endswith('.html')):
11377+
if size != expected_size and (f.endswith(('.js', '.html'))):
1137811378
print('Contents of ' + f + ': ')
1137911379
print(read_file(f))
1138011380

0 commit comments

Comments
 (0)