added ruff for code review

This commit is contained in:
ykcheungab
2026-09-27 19:21:03 +08:00
parent f91ac9d3db
commit e7dfd4f90b
28 changed files with 434 additions and 69 deletions
+2 -2
View File
@@ -16,8 +16,8 @@ from orisys_sensor_design.manifest import (
build_export_job,
build_manifest,
default_manifest_path,
export_revision_dir,
export_output_dir,
export_revision_dir,
load_profile,
repo_root,
validate_revision_metadata,
@@ -662,6 +662,7 @@ def cmd_optics(revision_dir: Path, args: argparse.Namespace) -> int:
)
return 2
from orisys_sensor_design.optics import REPORT_FILENAME as OPTICS_REPORT_FILENAME
from orisys_sensor_design.optics import (
OpticsConfigError,
build_report,
@@ -672,7 +673,6 @@ def cmd_optics(revision_dir: Path, args: argparse.Namespace) -> int:
summarize,
write_report,
)
from orisys_sensor_design.optics import REPORT_FILENAME as OPTICS_REPORT_FILENAME
want_plot = not args.no_plot
if want_plot:
+7 -3
View File
@@ -32,9 +32,10 @@ supplies one backed by the real stage helpers.
from __future__ import annotations
import json
from collections.abc import Callable, Mapping, Sequence
from dataclasses import dataclass, field
from pathlib import Path
from typing import Any, Callable, Mapping, Sequence
from typing import Any
SCHEMA = "orisys-sensor-design/settings-comparison-v1"
FILENAME = "settings_comparison.json"
@@ -410,7 +411,10 @@ def _probe_for(
changes["pattern"] = dataclasses_module.replace(
pattern, nx=int(entry.nx), ny=int(entry.ny), seed=int(entry.seed)
)
except Exception: # a non-dataclass pattern must not break the sweep
except Exception: # noqa: S110 - a non-dataclass pattern must not break the sweep
# Deliberate: ``dataclasses.replace`` only applies to dataclass
# patterns. A duck-typed/plain pattern keeps its defaults and the
# sweep continues; the run is still recorded under its own settings.
pass
return dataclasses_module.replace(settings, **changes)
@@ -651,7 +655,6 @@ def build_figures(
__all__ = [
"COMPARISON_DIRNAME",
"CompareError",
"DEFAULT_DIS_MODES",
"DEFAULT_GRID",
"DEFAULT_MAX_RUNS",
@@ -659,6 +662,7 @@ __all__ = [
"DEFAULT_SEEDS",
"FILENAME",
"SCHEMA",
"CompareError",
"SweepEntry",
"SweepOutcome",
"build_figures",
+2 -2
View File
@@ -26,10 +26,10 @@ Contract: ``docs/probe-pipeline.md``.
from __future__ import annotations
import json
from collections.abc import Mapping
from collections.abc import Mapping, Sequence
from dataclasses import dataclass, field
from pathlib import Path
from typing import Any, Sequence
from typing import Any
from orisys_sensor_design.manifest import RevisionPaths, export_object_names, load_yaml
from orisys_sensor_design.texture import (
+2 -1
View File
@@ -25,9 +25,10 @@ a 500x500 render. That ratio is the number the bench should be calibrated agains
from __future__ import annotations
from collections.abc import Mapping, Sequence
from dataclasses import dataclass
from pathlib import Path
from typing import Any, Iterable, Mapping, Sequence
from typing import Any
import numpy as np
+10 -4
View File
@@ -78,9 +78,10 @@ from __future__ import annotations
import json
import math
from collections.abc import Callable, Mapping, Sequence
from datetime import datetime, timezone
from pathlib import Path
from typing import Any, Callable, Mapping, Sequence
from typing import Any
import numpy as np
@@ -342,7 +343,9 @@ class FixedReferenceFlow:
if callable(getter):
try:
return int(getter())
except Exception: # pragma: no cover - defensive
except Exception: # noqa: S110 - defensive fallback to the documented default
# A binding whose getPatchSize() is missing or returns a non-numeric
# value reports the measured default instead of failing introspection.
pass
return DEFAULT_DIS_PATCH_PX
@@ -1706,8 +1709,11 @@ def run_track_job(
scale_output_dir = out / FLOW_DIRNAME / name
scale_output_dir.mkdir(parents=True, exist_ok=True)
def _save(flow_array: np.ndarray, frame_name: str) -> None:
np.save(scale_output_dir / f"{frame_name}.npy", flow_array.astype(np.float32))
# Bind the per-scale directory: it is reassigned for every ``name`` in
# the loop, so a late-bound closure would write every frame into the
# last scale's directory if these calls were ever deferred.
def _save(flow_array: np.ndarray, frame_name: str, out_dir: Path = scale_output_dir) -> None:
np.save(out_dir / f"{frame_name}.npy", flow_array.astype(np.float32))
_save(estimator.compute(reference), str(reference_entry.get("name", "reference")))
if null_path is not None:
+11 -9
View File
@@ -19,10 +19,12 @@ this module imports neither Blender nor cv2 and is testable in isolation.
from __future__ import annotations
import json
import math
from collections.abc import Callable, Mapping, Sequence
from dataclasses import dataclass
from datetime import datetime, timezone
from pathlib import Path
from typing import Any, Callable, Mapping, Sequence
from typing import Any
from orisys_sensor_design.manifest import RevisionPaths, repo_root
from orisys_sensor_design.sensitivity import (
@@ -88,19 +90,19 @@ ROI_CONFOUND_NOTE = (
)
__all__ = [
"OPTIMIZER_REPORT_SCHEMA",
"OPTIMIZER_REPORT_FILENAME",
"OPTIMIZER_OBJECTIVE",
"DEFAULT_GRID",
"DEFAULT_SEEDS",
"DEFAULT_SEARCH_RESOLUTION",
"NOT_GLOBAL_OPTIMUM",
"DEFAULT_SEEDS",
"GRID_RATIONALE",
"SCALE_DEPENDENT_NOTE",
"NOT_GLOBAL_OPTIMUM",
"OPTIMIZER_OBJECTIVE",
"OPTIMIZER_REPORT_FILENAME",
"OPTIMIZER_REPORT_SCHEMA",
"ROI_CONFOUND_NOTE",
"OptimiseError",
"SCALE_DEPENDENT_NOTE",
"Candidate",
"CandidateRun",
"OptimiseError",
"enumerate_candidates",
"rank_entries",
"run_optimise",
@@ -231,7 +233,7 @@ def _as_float(value: Any) -> float | None:
number = float(value)
except (TypeError, ValueError):
return None
if number != number: # NaN
if math.isnan(number):
return None
return number
+5 -1
View File
@@ -6,6 +6,7 @@ The viewport widget is kept separate from the chrome so it can be embedded later
from __future__ import annotations
import sys
from pathlib import Path
from typing import Any
@@ -132,7 +133,10 @@ def run_preview(
"""
from PyQt5.QtWidgets import QApplication
from orisys_sensor_design.preview.gl_view import PreviewGLWidget, configure_surface_format
from orisys_sensor_design.preview.gl_view import (
PreviewGLWidget,
configure_surface_format,
)
app = QApplication.instance()
created = app is None
+1 -3
View File
@@ -626,9 +626,7 @@ def analyse_map(
"passed": bool(max_ratio is not None and max_ratio <= settings.max_sliver_ratio),
},
]
if not uniform:
verdict = "inconclusive"
elif not material:
if not uniform or not material:
verdict = "inconclusive"
else:
verdict = "pass" if all(check["passed"] for check in checks) else "fail"
+2 -1
View File
@@ -34,8 +34,9 @@ comparison figure that quietly omits a failed setting is worse than no figure.
from __future__ import annotations
from collections.abc import Mapping, Sequence
from pathlib import Path
from typing import Any, Mapping, Sequence
from typing import Any
import numpy as np
+1 -1
View File
@@ -462,10 +462,10 @@ __all__ = [
"RENDER_JOB_SCHEMA",
"RENDER_MANIFEST_SCHEMA",
"REQUIRED_VIEW_TRANSFORM",
"ProbeConfigError",
"RenderArtifactError",
"RenderConfigError",
"RenderPaths",
"ProbeConfigError",
"build_render_job",
"default_render_paths",
"frame_name",
+23 -18
View File
@@ -20,14 +20,20 @@ from __future__ import annotations
import json
import math
from collections.abc import Callable, Mapping, Sequence
from dataclasses import dataclass
from datetime import datetime, timezone
from pathlib import Path
from typing import Any, Mapping, Sequence
from typing import Any
import numpy as np
from orisys_sensor_design.manifest import RevisionPaths, load_yaml, repo_root, sha256_file
from orisys_sensor_design.manifest import (
RevisionPaths,
load_yaml,
repo_root,
sha256_file,
)
from orisys_sensor_design.texture import texture_revision_rel
SENSITIVITY_REPORT_SCHEMA = "orisys-sensor-design/sensitivity-report-v2"
@@ -68,30 +74,29 @@ VERDICT_SEVERITY = {"ambiguous": -1, "unresolvable": 0, "marginal": 1, "resolvab
RESOLVABLE_SNR = 3.0
__all__ = [
"SENSITIVITY_REPORT_SCHEMA",
"SENSITIVITY_REPORT_FILENAME",
"DIS_PATCH_PX",
"min_local_scale_px_per_mm",
"MIN_LOCAL_SCALE_PX_PER_MM",
"SensitivityError",
"SensitivityConfigError",
"SensitivityDataError",
"SENSITIVITY_REPORT_FILENAME",
"SENSITIVITY_REPORT_SCHEMA",
"AxisScore",
"FrameFlow",
"MissingArtifactError",
"Roi",
"FrameFlow",
"AxisScore",
"ScaleScore",
"ScaleInput",
"ScaleScore",
"SensitivityConfigError",
"SensitivityDataError",
"SensitivityError",
"build_report",
"default_probe_output_dir",
"load_scale_inputs",
"min_local_scale_px_per_mm",
"resolution_pair",
"resolve_probe_output_dir",
"run_sensitivity",
"score_axis",
"score_scale",
"build_report",
"collect_report",
"run_sensitivity",
"write_sensitivity_report",
"load_scale_inputs",
"default_probe_output_dir",
"resolve_probe_output_dir",
"resolution_pair",
]