[CI][RFC] Replace black-jupyter with ruff-format (#37210)

Co-authored-by: Alison Shao <a.shao@wustl.edu>
This commit is contained in:
Alex Nails
2026-09-02 19:46:08 -07:00
committed by GitHub
co-authored by Alison Shao
parent 2641e427be
commit 28262c20df
1411 changed files with 7766 additions and 8176 deletions
@@ -541,7 +541,7 @@ FUSION_PATTERN_REGISTRY: Tuple[FusionPatternSpec, ...] = (
"fused_flashmla_metadata",
),
rationale_hint=(
"NSA replay metadata copies are already fused into one-kernel" " families."
"NSA replay metadata copies are already fused into one-kernel families."
),
min_share=0.02,
likely_share=0.2,
@@ -787,7 +787,7 @@ FUSION_PATTERN_REGISTRY: Tuple[FusionPatternSpec, ...] = (
("softmax", "sampling"),
),
rationale_hint=(
"Decode-time sampling already has fused temperature and softmax" " kernels."
"Decode-time sampling already has fused temperature and softmax kernels."
),
min_share=0.05,
likely_share=0.5,
@@ -1218,8 +1218,7 @@ FUSION_PATTERN_REGISTRY: Tuple[FusionPatternSpec, ...] = (
FusionPatternSpec(
pattern="vLLM fused residual add + RMSNorm",
candidate_path=(
"vllm/_custom_ops.py"
"<br>vllm/compilation/passes/fusion/rms_quant_fusion.py"
"vllm/_custom_ops.py<br>vllm/compilation/passes/fusion/rms_quant_fusion.py"
),
active_keywords=(
"fused_add_rms_norm",
@@ -1236,8 +1235,7 @@ FUSION_PATTERN_REGISTRY: Tuple[FusionPatternSpec, ...] = (
FusionPatternSpec(
pattern="vLLM fused activation-and-mul",
candidate_path=(
"vllm/_custom_ops.py"
"<br>vllm/compilation/passes/fusion/act_quant_fusion.py"
"vllm/_custom_ops.py<br>vllm/compilation/passes/fusion/act_quant_fusion.py"
),
active_keywords=(
"silu_and_mul",
@@ -256,7 +256,9 @@ def _module_assign_names(text: str) -> set:
targets = (
node.targets
if isinstance(node, ast.Assign)
else [node.target] if isinstance(node, ast.AnnAssign) else []
else [node.target]
if isinstance(node, ast.AnnAssign)
else []
)
names |= {t.id for t in targets if isinstance(t, ast.Name)}
return names
@@ -173,9 +173,9 @@ def _find_unique_def(
if isinstance(node, definition) and node.name == name
]
assert matches, f"{name} not found in {where}"
assert (
len(matches) == 1
), f"{len(matches)} defs named {name} in {where}; pass from_class to disambiguate"
assert len(matches) == 1, (
f"{len(matches)} defs named {name} in {where}; pass from_class to disambiguate"
)
return matches[0]
@@ -287,9 +287,9 @@ def _lowered_call_text(text: str, node: ast.Call) -> str:
"""
receiver = node.args[0]
receiver_src = _node_slice(text, receiver)
assert (
"\n" not in receiver_src and "#" not in receiver_src
), f"receiver {receiver_src!r} must be single-line and comment-free"
assert "\n" not in receiver_src and "#" not in receiver_src, (
f"receiver {receiver_src!r} must be single-line and comment-free"
)
opener = _slice_span(
text,
node.func.end_lineno,
@@ -722,9 +722,9 @@ class Repro:
)
existing = [alias_text(a.name, a.asname) for a in node.names]
added = alias_text(name, asname)
assert (
added not in existing
), f"{name!r} already imported from {module!r} in {rel}"
assert added not in existing, (
f"{name!r} already imported from {module!r} in {rel}"
)
rebuilt = f"from {module} import " + ", ".join(existing + [added]) + nl
lines[node.lineno - 1 : node.end_lineno] = [rebuilt]
_write_source(path, "".join(lines))
@@ -825,9 +825,9 @@ class Repro:
for node in tree.body
if isinstance(node, (ast.Import, ast.ImportFrom))
]
assert (
imports
), f"no imports to anchor a new `if TYPE_CHECKING:` block in {rel}"
assert imports, (
f"no imports to anchor a new `if TYPE_CHECKING:` block in {rel}"
)
insert_at = imports[-1].end_lineno
lines[insert_at:insert_at] = [
nl,
@@ -864,9 +864,9 @@ class Repro:
replaced = lines[node.lineno - 1].replace(
f"from {spelled} import", f"from {new_module} import", 1
)
assert (
replaced != lines[node.lineno - 1]
), f"import spelling {spelled!r} not found on its line in {rel}"
assert replaced != lines[node.lineno - 1], (
f"import spelling {spelled!r} not found on its line in {rel}"
)
lines[node.lineno - 1] = replaced
changed = True
assert changed, f"nested import of {name} from {old_module} not in {rel}"
@@ -974,9 +974,9 @@ class Repro:
``self: Target`` annotation is dropped (redundant inside the class). The body is moved
verbatim; the formatter normalises the surrounding blank lines.
"""
assert (
before is None or after is None
), "move_symbol: before and after are mutually exclusive"
assert before is None or after is None, (
"move_symbol: before and after are mutually exclusive"
)
def op(root: Path) -> None:
src_path = root / src
@@ -1255,15 +1255,17 @@ class Repro:
targets = (
node.targets
if isinstance(node, ast.Assign)
else [node.target] if isinstance(node, ast.AnnAssign) else []
else [node.target]
if isinstance(node, ast.AnnAssign)
else []
)
names = {t.id for t in targets if isinstance(t, ast.Name)}
hit = names & dropped
if not hit:
continue
assert len(names) == len(
targets
), f"drop_assigns {sorted(hit)}: non-name targets in {src}"
assert len(names) == len(targets), (
f"drop_assigns {sorted(hit)}: non-name targets in {src}"
)
value_src = ast.unparse(node.value) if node.value is not None else None
for dropped_name in hit:
removed_assigns[dropped_name] = value_src
@@ -1289,15 +1291,17 @@ class Repro:
else:
assign_spans.append((node.lineno, node.end_lineno))
found_assigns |= hit
assert (
found_assigns == dropped
), f"{dropped - found_assigns} not assigned in {src}"
assert found_assigns == dropped, (
f"{dropped - found_assigns} not assigned in {src}"
)
rederivable: dict[str, str | None] = {}
for node in tree.body:
targets = (
node.targets
if isinstance(node, ast.Assign)
else [node.target] if isinstance(node, ast.AnnAssign) else []
else [node.target]
if isinstance(node, ast.AnnAssign)
else []
)
names = [t.id for t in targets if isinstance(t, ast.Name)]
if not names or set(names) & dropped:
@@ -1383,9 +1387,9 @@ class Repro:
src_text = _read_source(src_path)
assert src_text.count(body) == 1, f"block not found uniquely in {src}"
at = src_text.find(body)
assert (
at == 0 or src_text[at - 1] == "\n"
), f"block matches mid-line in {src}; it must start at a line boundary"
assert at == 0 or src_text[at - 1] == "\n", (
f"block matches mid-line in {src}; it must start at a line boundary"
)
_write_source(src_path, src_text.replace(body, call, 1))
dst_path = root / dst
@@ -370,12 +370,7 @@ def test_infer_recipe_module_level_def_shadowed_by_method_name(repo: Path) -> No
" return foo(x=self.x)\n"
),
"util.py": (
"def keep():\n"
" return 1\n"
"\n"
"\n"
"def foo(*, x):\n"
" return x + 1\n"
"def keep():\n return 1\n\n\ndef foo(*, x):\n return x + 1\n"
),
},
)
@@ -437,9 +432,7 @@ def test_infer_recipe_move_leaving_a_forwarding_delegate(repo: Path) -> None:
_write(
repo,
**{
"model.py": (
"class M:\n" " def work(self, x):\n" " return x + 1\n"
),
"model.py": ("class M:\n def work(self, x):\n return x + 1\n"),
"comp.py": "class C:\n def keep(self):\n return 1\n",
},
)
@@ -448,9 +441,7 @@ def test_infer_recipe_move_leaving_a_forwarding_delegate(repo: Path) -> None:
repo,
**{
"model.py": (
"class M:\n"
" def work(self, x):\n"
" return self.comp.work(x)\n"
"class M:\n def work(self, x):\n return self.comp.work(x)\n"
),
"comp.py": (
"class C:\n"
@@ -2,13 +2,9 @@ import subprocess
from pathlib import Path
_PASSING_PROOF = (
"import sys\n"
'print("PASS: reproduces the commit byte-for-byte.")\n'
"sys.exit(0)\n"
)
_FAILING_PROOF = (
"import sys\n" 'print("RESIDUAL (2 lines):\\n+x\\n-y")\n' "sys.exit(1)\n"
'import sys\nprint("PASS: reproduces the commit byte-for-byte.")\nsys.exit(0)\n'
)
_FAILING_PROOF = 'import sys\nprint("RESIDUAL (2 lines):\\n+x\\n-y")\nsys.exit(1)\n'
def _git(repo: Path, *args: str) -> str:
@@ -110,13 +110,7 @@ def test_add_typechecking_import_inserts_in_block(tmp_path: Path) -> None:
def test_add_typechecking_import_creates_missing_block(tmp_path: Path) -> None:
"""With no TYPE_CHECKING block, one is created after the trailing module import."""
(tmp_path / "m.py").write_text(
"from typing import TYPE_CHECKING\n"
"\n"
"from a import X\n"
"\n"
"\n"
"def f():\n"
" pass\n"
"from typing import TYPE_CHECKING\n\nfrom a import X\n\n\ndef f():\n pass\n"
)
r = Repro("b", "t").add_typechecking_import("m.py", "from b import Y")
_apply(r, tmp_path)
@@ -215,12 +209,7 @@ def test_add_typechecking_import_raises_without_imports(tmp_path: Path) -> None:
def test_add_typechecking_import_drops_a_lone_pass_placeholder(tmp_path: Path) -> None:
"""Populating a `pass`-only TYPE_CHECKING block replaces the placeholder."""
(tmp_path / "m.py").write_text(
"from typing import TYPE_CHECKING\n"
"\n"
"if TYPE_CHECKING:\n"
" pass\n"
"\n"
"x = 1\n"
"from typing import TYPE_CHECKING\n\nif TYPE_CHECKING:\n pass\n\nx = 1\n"
)
r = Repro("b", "t").add_typechecking_import("m.py", "from b import Y")
_apply(r, tmp_path)
@@ -111,11 +111,7 @@ def test_extract_symbols_to_new_module_drops_relocated_assigns(tmp_path: Path) -
" return _FLAG\n"
)
header = (
"from __future__ import annotations\n"
"\n"
"import os\n"
"\n"
"_FLAG = os.cpu_count()\n"
"from __future__ import annotations\n\nimport os\n\n_FLAG = os.cpu_count()\n"
)
r = Repro("b", "t").extract_symbols_to_new_module(
"src.py",
@@ -19,13 +19,7 @@ def test_move_assign_relocates_a_module_constant(tmp_path: Path) -> None:
_apply(r, tmp_path)
assert "LIMIT" not in (tmp_path / "src.py").read_text().split("def stay")[0]
assert (tmp_path / "dst.py").read_text() == (
"import sys\n"
"\n"
"LIMIT = 480 # seconds\n"
"\n"
"\n"
"def keep():\n"
" return 1\n"
"import sys\n\nLIMIT = 480 # seconds\n\n\ndef keep():\n return 1\n"
)
@@ -50,13 +44,7 @@ def test_move_assign_relocates_an_annotated_constant(tmp_path: Path) -> None:
_apply(r, tmp_path)
assert "LIMIT" not in (tmp_path / "src.py").read_text().split("def stay")[0]
assert (tmp_path / "dst.py").read_text() == (
"import sys\n"
"\n"
"LIMIT: int = 480\n"
"\n"
"\n"
"def keep():\n"
" return 1\n"
"import sys\n\nLIMIT: int = 480\n\n\ndef keep():\n return 1\n"
)
@@ -260,13 +260,7 @@ def test_move_symbol_dedent_leaves_string_literal_interior_lines(
)
_apply(r, tmp_path)
assert (tmp_path / "dst.py").read_text() == (
"import os\n"
"\n"
"def foo(self):\n"
" s = '''raw\n"
" partial\n"
"'''\n"
" return s\n"
"import os\n\ndef foo(self):\n s = '''raw\n partial\n'''\n return s\n"
)
@@ -101,8 +101,7 @@ def format_summary_line(filename: str, result: Dict[str, Any]) -> str:
if result.get("ok"):
return f"{filename}: ok"
return (
f"{filename}: failed status={result.get('status')} "
f"error={result.get('error')}"
f"{filename}: failed status={result.get('status')} error={result.get('error')}"
)
@@ -617,7 +616,9 @@ def summarize_dump_file(path: Path, max_requests: int, preview_chars: int) -> st
time_span = (
max(timestamps) - min(timestamps)
if len(timestamps) >= 2
else 0.0 if len(timestamps) == 1 else None
else 0.0
if len(timestamps) == 1
else None
)
lines = [