From 56d0ea288373557c30c61443415e74641f218f08 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 12 Apr 2026 19:09:23 +0000 Subject: [PATCH] fix: use importlib for radar_protocol import; downgrade noisy log levels to DEBUG Agent-Logs-Url: https://github.com/NawfalMotii79/PLFM_RADAR/sessions/8acb5f68-51fa-4632-a73b-0188b876bed1 Co-authored-by: JJassonn69 <83615043+JJassonn69@users.noreply.github.com> --- 9_Firmware/9_3_GUI/v7/hardware.py | 42 +++++++++++++++++++---------- 9_Firmware/9_3_GUI/v7/map_widget.py | 7 ++--- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/9_Firmware/9_3_GUI/v7/hardware.py b/9_Firmware/9_3_GUI/v7/hardware.py index e0231ef..b9b4109 100644 --- a/9_Firmware/9_3_GUI/v7/hardware.py +++ b/9_Firmware/9_3_GUI/v7/hardware.py @@ -13,9 +13,10 @@ and 'SET'...'END' binary settings protocol has been removed — it was incompatible with the FPGA register interface. """ -import sys -import os +import importlib.util import logging +import pathlib +import sys from typing import ClassVar from .models import USB_AVAILABLE @@ -24,18 +25,31 @@ if USB_AVAILABLE: import usb.core import usb.util -# Import production protocol layer — single source of truth for FPGA comms -sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) -from radar_protocol import ( # noqa: F401 — re-exported for v7 package - FT2232HConnection, - ReplayConnection, - RadarProtocol, - Opcode, - RadarAcquisition, - RadarFrame, - StatusResponse, - DataRecorder, -) + +def _load_radar_protocol(): + """Load radar_protocol.py by absolute path without mutating sys.path.""" + mod_name = "radar_protocol" + if mod_name in sys.modules: + return sys.modules[mod_name] + proto_path = pathlib.Path(__file__).resolve().parent.parent / "radar_protocol.py" + spec = importlib.util.spec_from_file_location(mod_name, proto_path) + mod = importlib.util.module_from_spec(spec) + sys.modules[mod_name] = mod + spec.loader.exec_module(mod) # type: ignore[union-attr] + return mod + + +_rp = _load_radar_protocol() + +# Re-exported for the v7 package — single source of truth for FPGA comms +FT2232HConnection = _rp.FT2232HConnection +ReplayConnection = _rp.ReplayConnection +RadarProtocol = _rp.RadarProtocol +Opcode = _rp.Opcode +RadarAcquisition = _rp.RadarAcquisition +RadarFrame = _rp.RadarFrame +StatusResponse = _rp.StatusResponse +DataRecorder = _rp.DataRecorder logger = logging.getLogger(__name__) diff --git a/9_Firmware/9_3_GUI/v7/map_widget.py b/9_Firmware/9_3_GUI/v7/map_widget.py index 08a6b04..08b1e9e 100644 --- a/9_Firmware/9_3_GUI/v7/map_widget.py +++ b/9_Firmware/9_3_GUI/v7/map_widget.py @@ -64,7 +64,7 @@ class MapBridge(QObject): @pyqtSlot(str) def logFromJS(self, message: str): - logger.info(f"[JS] {message}") + logger.debug(f"[JS] {message}") @property def is_ready(self) -> bool: @@ -578,10 +578,7 @@ document.addEventListener('DOMContentLoaded', function() {{ return data = [t.to_dict() for t in targets] js_payload = json.dumps(data).replace("\\", "\\\\").replace("'", "\\'") - logger.info( - "set_targets: %d targets, JSON len=%d, first 200 chars: %s", - len(targets), len(js_payload), js_payload[:200], - ) + logger.debug("set_targets: %d targets", len(targets)) self._status_label.setText(f"{len(targets)} targets tracked") self._run_js(f"updateTargets('{js_payload}')")