added ruff code reivew
This commit is contained in:
@@ -22,7 +22,6 @@ import os
|
||||
import sys
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
@@ -35,7 +34,6 @@ for path in (REPO_ROOT, SRC_ROOT):
|
||||
|
||||
from orisys.tracker import Tracker # noqa: E402
|
||||
|
||||
|
||||
DEFAULT_CONFIG = "box"
|
||||
|
||||
|
||||
@@ -125,7 +123,7 @@ class FixedRefDIS:
|
||||
preset = dis_preset_from_name(config_tracker.get("dis_preset", "medium"))
|
||||
self._dis = cv2.DISOpticalFlow_create(preset)
|
||||
self._dis.setFinestScale(int(config_tracker.get("dis_mode", 3)))
|
||||
self._ref: Optional[np.ndarray] = None
|
||||
self._ref: np.ndarray | None = None
|
||||
|
||||
def reset(self) -> None:
|
||||
self._ref = None
|
||||
@@ -148,7 +146,7 @@ def make_tracker(config_tracker: dict, *, adaptive: bool) -> Tracker:
|
||||
)
|
||||
|
||||
|
||||
def read_gray_frame(cap: cv2.VideoCapture, static_image: Optional[np.ndarray]) -> tuple[bool, Optional[np.ndarray]]:
|
||||
def read_gray_frame(cap: cv2.VideoCapture, static_image: np.ndarray | None) -> tuple[bool, np.ndarray | None]:
|
||||
if static_image is not None:
|
||||
return True, static_image.copy()
|
||||
ok, frame = cap.read()
|
||||
@@ -164,11 +162,11 @@ def run_comparison(
|
||||
*,
|
||||
config_tracker: dict,
|
||||
max_frames: int,
|
||||
reset_every: Optional[int],
|
||||
reset_every: int | None,
|
||||
show: bool,
|
||||
) -> dict[str, ModeSeries]:
|
||||
path = Path(str(source)) if isinstance(source, str) else None
|
||||
static_image: Optional[np.ndarray] = None
|
||||
static_image: np.ndarray | None = None
|
||||
if isinstance(source, str) and path is not None and path.is_file():
|
||||
img = cv2.imread(str(path), cv2.IMREAD_GRAYSCALE)
|
||||
if img is not None:
|
||||
|
||||
+3
-1
@@ -114,7 +114,9 @@ def test_config_name() -> str:
|
||||
try:
|
||||
if _is_usable_config(name):
|
||||
return name
|
||||
except Exception:
|
||||
except Exception: # noqa: S112 - a failing config is simply not a candidate
|
||||
# Probe: a config that cannot be loaded or lacks the key is simply not
|
||||
# a candidate. Any such failure is reported if no config survives.
|
||||
continue
|
||||
|
||||
raise RuntimeError(
|
||||
|
||||
@@ -20,6 +20,7 @@ os.environ["OPENCV_VIDEOIO_MSMF_ENABLE_HW_TRANSFORMS"] = "0"
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
import orisys
|
||||
|
||||
_REPO_ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
@@ -10,8 +10,8 @@ import pytest
|
||||
|
||||
from orisys import Sensor
|
||||
from orisys.calibration import (
|
||||
CalSample,
|
||||
CalibrationError,
|
||||
CalSample,
|
||||
build,
|
||||
check,
|
||||
filter_mismatches,
|
||||
|
||||
@@ -22,9 +22,8 @@ from orisys.capture import (
|
||||
open_capture,
|
||||
pick_default_camera,
|
||||
)
|
||||
from orisys.capture.source import _apply_stream_props, _warmup_capture
|
||||
from orisys.capture.discovery import DEFAULT_LAPTOP_WEBCAM_PATTERNS
|
||||
|
||||
from orisys.capture.source import _apply_stream_props, _warmup_capture
|
||||
|
||||
MJPG = cv2.VideoWriter_fourcc(*"MJPG")
|
||||
YUY2 = cv2.VideoWriter_fourcc(*"YUY2")
|
||||
|
||||
@@ -6,8 +6,8 @@ if str(_EXAMPLES) not in sys.path:
|
||||
sys.path.insert(0, str(_EXAMPLES))
|
||||
|
||||
from viz.contact_arrow import (
|
||||
ContactArrowStyle,
|
||||
DEFAULT_CONTACT_ARROW_STYLE,
|
||||
ContactArrowStyle,
|
||||
force_visual_strength,
|
||||
length_from_force,
|
||||
thickness_scale_from_force,
|
||||
|
||||
@@ -4,7 +4,6 @@ from __future__ import annotations
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from orisys.util import _prepare_draw_mask, draw_arrows
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ import pytest
|
||||
|
||||
from orisys import FrameSnapshot, StreamRecorder, mosaic_videos
|
||||
|
||||
|
||||
_DEFAULT = object()
|
||||
|
||||
|
||||
@@ -156,7 +155,6 @@ def test_valid_mask_callable_resolved_per_frame(tmp_path):
|
||||
|
||||
def mask():
|
||||
calls.append(1)
|
||||
return None
|
||||
|
||||
path = str(tmp_path / "s0.mp4")
|
||||
rec = StreamRecorder(path, grid_spacing=8, overlay_values=False, valid_mask=mask)
|
||||
|
||||
@@ -16,9 +16,9 @@ from pathlib import Path
|
||||
import pytest
|
||||
|
||||
from orisys import Sensor
|
||||
from orisys import configs as orisys_configs
|
||||
from orisys.calibration import filters_fingerprint
|
||||
from orisys.sensor import FILTER_PRESETS, available_filter_presets
|
||||
from orisys import configs as orisys_configs
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parents[1]
|
||||
EXAMPLES = REPO_ROOT / "examples" / "filters"
|
||||
|
||||
@@ -4,7 +4,11 @@ import numpy as np
|
||||
import pytest
|
||||
|
||||
import orisys
|
||||
from orisys.finger import TactileProcessor, load_finger_export_bundle, resolve_export_paths
|
||||
from orisys.finger import (
|
||||
TactileProcessor,
|
||||
load_finger_export_bundle,
|
||||
resolve_export_paths,
|
||||
)
|
||||
from orisys.finger.exports import DEFAULT_FINGER_MAP_CACHE
|
||||
from orisys.finger.runtime import resolve_finger_geometry
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import pytest
|
||||
from orisys.backend_availability import CUPY_AVAILABLE
|
||||
from orisys.hhd import PoissonSolver, nHHD
|
||||
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
|
||||
@@ -12,7 +12,11 @@ def packaging_utils():
|
||||
build_dir = REPO_ROOT / "build"
|
||||
if str(build_dir) not in sys.path:
|
||||
sys.path.insert(0, str(build_dir))
|
||||
from common.pyproject_utils import extras_require, install_requires, project_metadata
|
||||
from common.pyproject_utils import (
|
||||
extras_require,
|
||||
install_requires,
|
||||
project_metadata,
|
||||
)
|
||||
|
||||
return install_requires, extras_require, project_metadata
|
||||
|
||||
|
||||
@@ -15,6 +15,11 @@ _EXAMPLES_DIR = _REPO_ROOT / "examples"
|
||||
if str(_EXAMPLES_DIR) not in sys.path:
|
||||
sys.path.insert(0, str(_EXAMPLES_DIR))
|
||||
|
||||
from gui.sensors import ( # noqa: E402
|
||||
FrameSnapshot,
|
||||
_snapshot_from_sensor,
|
||||
calibrate_normal_force,
|
||||
)
|
||||
from gui.viewer2d.backend import ( # noqa: E402
|
||||
QtViewerBackend,
|
||||
image_shape_meta,
|
||||
@@ -22,12 +27,10 @@ from gui.viewer2d.backend import ( # noqa: E402
|
||||
scale_bgr_to_fit,
|
||||
select_display_image,
|
||||
)
|
||||
from gui.sensors import ( # noqa: E402
|
||||
FrameSnapshot,
|
||||
_snapshot_from_sensor,
|
||||
calibrate_normal_force,
|
||||
|
||||
from orisys.signal_processing import (
|
||||
calibrate_normal_force as sdk_calibrate_normal_force,
|
||||
)
|
||||
from orisys.signal_processing import calibrate_normal_force as sdk_calibrate_normal_force
|
||||
|
||||
|
||||
class FakeForceAdapter:
|
||||
|
||||
@@ -9,8 +9,6 @@ import sys
|
||||
import urllib.error
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parents[1]
|
||||
BUILD_ROOT = REPO_ROOT / "build"
|
||||
if str(BUILD_ROOT) not in sys.path:
|
||||
|
||||
@@ -5,7 +5,7 @@ from __future__ import annotations
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from orisys.Stitcher import Stitcher
|
||||
from orisys.frame_processors import CompoundEyeFrameProcessor
|
||||
from orisys.stitch import (
|
||||
StitchStatus,
|
||||
get_blend_backend,
|
||||
@@ -16,7 +16,7 @@ from orisys.stitch import (
|
||||
from orisys.stitch.backends.numpy_backend import blend_kernel_numpy
|
||||
from orisys.stitch.config import numba_blend_available, validate_box_grid
|
||||
from orisys.stitch.ops import compute_final_crop_rect, coverage_ratio
|
||||
from orisys.frame_processors import CompoundEyeFrameProcessor
|
||||
from orisys.Stitcher import Stitcher
|
||||
|
||||
|
||||
def _solid_tile(val: int, h=32, w=32):
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from orisys.finger.mesh import (
|
||||
build_uv_surface_mesh,
|
||||
|
||||
@@ -3,8 +3,13 @@ from pathlib import Path
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from orisys.unroll import UVDomain, UVRemap, UVSurfaceMap, flatten_frame, remap_valid_ratio
|
||||
|
||||
from orisys.unroll import (
|
||||
UVDomain,
|
||||
UVRemap,
|
||||
UVSurfaceMap,
|
||||
flatten_frame,
|
||||
remap_valid_ratio,
|
||||
)
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parents[1]
|
||||
UV_MAP_PATH = REPO_ROOT / "unroll_map_uv.npz"
|
||||
|
||||
@@ -7,7 +7,6 @@ import pytest
|
||||
from orisys.frame_processors import FrameUnwarper
|
||||
from orisys.unroll import UVDomain
|
||||
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parents[1]
|
||||
UV_MAP_PATH = REPO_ROOT / "unroll_map_uv.npz"
|
||||
|
||||
|
||||
@@ -12,14 +12,16 @@ import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parents[1]
|
||||
BUILD_ROOT = REPO_ROOT / "build"
|
||||
if str(BUILD_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(BUILD_ROOT))
|
||||
|
||||
from wheel.package import metadata_kwargs, read_long_description, write_wheel_setup # noqa: E402
|
||||
from wheel.package import ( # noqa: E402
|
||||
metadata_kwargs,
|
||||
read_long_description,
|
||||
write_wheel_setup,
|
||||
)
|
||||
|
||||
PROJECT = {
|
||||
"name": "orisys",
|
||||
|
||||
Reference in New Issue
Block a user