style: clean lint warnings introduced by parallel-queue change

- Drop unused `import json` from new test module (F401).
- Remove unused `# noqa: BLE001` directives — project ruff config doesn't
  enable BLE001 so the suppressions were dead weight (RUF100 x3).
- Replace `×` (U+00D7) with ASCII `x` in console output (RUF001).
- Collapse seed-strategy if/else into ternary (SIM108).
- Use `enumerate(as_completed(...), start=1)` for completion counter
  instead of manual `completed = 0; completed += 1` (SIM113).
- Run `ruff format` on touched files.

Pre-existing lint errors on master (PLC0415/PLR0915/SIM113 in unrelated
commands) are untouched — separate cleanup PR if desired. Net delta of
this branch over master: 0 new lint errors.

All 374 tests still passing.
This commit is contained in:
2026-05-18 23:34:22 +02:00
parent 6ddcf84167
commit 2ca9003f86
2 changed files with 14 additions and 26 deletions
+12 -19
View File
@@ -927,8 +927,7 @@ def generate( # noqa: PLR0915
# files, each task must take the non-JSON path. We render our own JSON # files, each task must take the non-JSON path. We render our own JSON
# at the end, so the per-task --json is incompatible. # at the end, so the per-task --json is incompatible.
console.print( console.print(
"[red]--json is not supported with --parallel-queue > 1 " "[red]--json is not supported with --parallel-queue > 1 (would skip the file-save step). Drop one or the other.[/red]"
"(would skip the file-save step). Drop one or the other.[/red]"
) )
raise typer.Exit(1) raise typer.Exit(1)
# ---- --input merging (JSON or YAML) ---- # ---- --input merging (JSON or YAML) ----
@@ -1086,7 +1085,7 @@ def generate( # noqa: PLR0915
with Database() as _db: with Database() as _db:
_db.init_schema() _db.init_schema()
_base_model = _db.get_base_model_by_filename(model) _base_model = _db.get_base_model_by_filename(model)
except Exception: # noqa: BLE001 except Exception:
pass pass
_detected = detect_model_family(model, _base_model) _detected = detect_model_family(model, _base_model)
_fam = family or _detected _fam = family or _detected
@@ -1099,10 +1098,7 @@ def generate( # noqa: PLR0915
# --seed >= 0 → use as base, increment per job (reproducible series) # --seed >= 0 → use as base, increment per job (reproducible series)
# --seed == -1 → pick a fresh random seed PER JOB so parallel runs aren't # --seed == -1 → pick a fresh random seed PER JOB so parallel runs aren't
# accidentally correlated (each thread gets variety) # accidentally correlated (each thread gets variety)
if seed >= 0: seeds = [seed + i for i in range(count)] if seed >= 0 else [_rng.randint(0, 2**32 - 1) for _ in range(count)]
seeds = [seed + i for i in range(count)]
else:
seeds = [_rng.randint(0, 2**32 - 1) for _ in range(count)]
# Output paths: mirror the existing `count > 1` naming convention from # Output paths: mirror the existing `count > 1` naming convention from
# _run_generation (stem_NNN.ext). When --output is omitted, leave per-task # _run_generation (stem_NNN.ext). When --output is omitted, leave per-task
@@ -1117,8 +1113,7 @@ def generate( # noqa: PLR0915
if not json_output: if not json_output:
console.print( console.print(
f"[dim]Parallel queue: {effective_parallel} concurrent submissions " f"[dim]Parallel queue: {effective_parallel} concurrent submissions x {count} images (output may interleave)[/dim]"
f"× {count} images (output may interleave)[/dim]"
) )
common_kwargs: dict[str, Any] = { common_kwargs: dict[str, Any] = {
@@ -1171,7 +1166,7 @@ def generate( # noqa: PLR0915
except typer.Exit as ex: except typer.Exit as ex:
result["duration_sec"] = round(_time.perf_counter() - start, 2) result["duration_sec"] = round(_time.perf_counter() - start, 2)
result["error"] = f"generate exited with code {ex.exit_code}" result["error"] = f"generate exited with code {ex.exit_code}"
except Exception as ex: # noqa: BLE001 except Exception as ex:
result["duration_sec"] = round(_time.perf_counter() - start, 2) result["duration_sec"] = round(_time.perf_counter() - start, 2)
result["error"] = str(ex) result["error"] = str(ex)
return result return result
@@ -1179,12 +1174,13 @@ def generate( # noqa: PLR0915
fan_results: list[dict[str, Any]] = [] fan_results: list[dict[str, Any]] = []
with ThreadPoolExecutor(max_workers=effective_parallel) as pool: with ThreadPoolExecutor(max_workers=effective_parallel) as pool:
futures = {pool.submit(_run_one, i): i for i in range(count)} futures = {pool.submit(_run_one, i): i for i in range(count)}
completed = 0 for completed, fut in enumerate(as_completed(futures), start=1):
for fut in as_completed(futures):
completed += 1
try: try:
res = fut.result() res = fut.result()
except Exception as ex: # noqa: BLE001 — defensive; _run_one already swallows except Exception as ex:
# Defensive — _run_one already swallows, but if the executor itself
# raises (e.g. pickling failure) we still want a well-formed result
# in the manifest rather than a crash.
res = { res = {
"index": futures[fut], "index": futures[fut],
"seed": seeds[futures[fut]], "seed": seeds[futures[fut]],
@@ -1198,13 +1194,10 @@ def generate( # noqa: PLR0915
if res["success"]: if res["success"]:
where = res["output"] or "(no --output set)" where = res["output"] or "(no --output set)"
console.print( console.print(
f"[green]\\[{completed}/{count}] seed={res['seed']} " f"[green]\\[{completed}/{count}] seed={res['seed']} ok in {res['duration_sec']:.1f}s → {where}[/green]"
f"ok in {res['duration_sec']:.1f}s → {where}[/green]"
) )
else: else:
console.print( console.print(f"[red]\\[{completed}/{count}] seed={res['seed']} FAIL: {res['error']}[/red]")
f"[red]\\[{completed}/{count}] seed={res['seed']} FAIL: {res['error']}[/red]"
)
# Reorder by original index so JSON output / final summary list is stable. # Reorder by original index so JSON output / final summary list is stable.
fan_results.sort(key=lambda r: r["index"]) fan_results.sort(key=lambda r: r["index"])
+2 -7
View File
@@ -2,7 +2,6 @@
from __future__ import annotations from __future__ import annotations
import json
from pathlib import Path from pathlib import Path
from typing import Any from typing import Any
@@ -258,9 +257,7 @@ def test_parallel_queue_from_yaml_input(tmp_path: Path, calls: list[dict[str, An
"""parallel_queue can be set via --input YAML (mirrors other generate params).""" """parallel_queue can be set via --input YAML (mirrors other generate params)."""
out = tmp_path / "img.png" out = tmp_path / "img.png"
yml = tmp_path / "spec.yml" yml = tmp_path / "spec.yml"
yml.write_text( yml.write_text(f'prompt: from-yaml\nmodel: x.safetensors\ncount: 3\nparallel_queue: 3\nseed: 7\noutput: "{out}"\n')
f'prompt: from-yaml\nmodel: x.safetensors\ncount: 3\nparallel_queue: 3\nseed: 7\noutput: "{out}"\n'
)
result = runner.invoke(app, ["generate", "--input", str(yml)]) result = runner.invoke(app, ["generate", "--input", str(yml)])
assert result.exit_code == 0, result.output assert result.exit_code == 0, result.output
assert len(calls) == 3 assert len(calls) == 3
@@ -271,9 +268,7 @@ def test_cli_parallel_queue_overrides_yaml(tmp_path: Path, calls: list[dict[str,
"""CLI --parallel-queue wins over YAML's parallel_queue (standard precedence).""" """CLI --parallel-queue wins over YAML's parallel_queue (standard precedence)."""
out = tmp_path / "img.png" out = tmp_path / "img.png"
yml = tmp_path / "spec.yml" yml = tmp_path / "spec.yml"
yml.write_text( yml.write_text(f'prompt: from-yaml\nmodel: x.safetensors\ncount: 2\nparallel_queue: 1\nseed: 10\noutput: "{out}"\n')
f'prompt: from-yaml\nmodel: x.safetensors\ncount: 2\nparallel_queue: 1\nseed: 10\noutput: "{out}"\n'
)
# YAML says P=1 (sequential), CLI overrides to P=2 (fanout) # YAML says P=1 (sequential), CLI overrides to P=2 (fanout)
result = runner.invoke(app, ["generate", "--input", str(yml), "-P", "2"]) result = runner.invoke(app, ["generate", "--input", str(yml), "-P", "2"])
assert result.exit_code == 0, result.output assert result.exit_code == 0, result.output