Răsfoiți Sursa

fix(leds): cap Adafruit-Blinka <10 and surface its import errors (v4.1.5) (#147)

Blinka 10 (released 2026-10-26) checks platform libraries when `board` is
imported. On any Raspberry Pi it refuses to start unless Python gpiod is
>=2.2.2,<3. Fresh installs since then pull Blinka 10, so a venv with an
older gpiod breaks DW LEDs with "Blinka found installed platform
dependencies with unsupported versions".

- requirements.txt: cap Adafruit-Blinka <10. `dw update` runs a plain
  `pip install -r`, so venvs that already have Blinka 10 are downgraded
  to 9.2.0, the version line that worked before the break.
- dw_led_controller: the Pi 5 fallback re-imports `board`, which raises
  the same RuntimeError. It only caught ImportError, so the exception
  escaped `_initialize_hardware` instead of being reported as
  `_init_error`. It now catches RuntimeError too.
- Install hint now recommends 'adafruit-blinka<10'.
- Regression test for the RuntimeError path.

Verified in a linux/arm64 Python 3.11 container that faked a Pi 4B and a
Pi 5. It reproduced the customer's error and the uncaught exception, then
confirmed that the update step downgrades Blinka and `import board`
succeeds. Not verified on real LED hardware.

Bump VERSION to 4.1.5.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Tuan Nguyen 1 zi în urmă
părinte
comite
8997ddd94c
4 a modificat fișierele cu 24 adăugiri și 4 ștergeri
  1. 1 1
      VERSION
  2. 2 2
      modules/led/dw_led_controller.py
  3. 1 1
      requirements.txt
  4. 20 0
      tests/unit/test_dw_led_controller.py

+ 1 - 1
VERSION

@@ -1 +1 @@
-4.1.4
+4.1.5

+ 2 - 2
modules/led/dw_led_controller.py

@@ -79,12 +79,12 @@ class DWLEDController:
                 neopixel_module = neopixel_pi5
                 using_pi5_library = True
                 logger.info("Using Adafruit Pi 5 NeoPixel library (PIO-based)")
-            except ImportError as e2:
+            except (ImportError, RuntimeError) as e2:  # `import board` re-raises Blinka's RuntimeError here
                 error_msg = (
                     f"Failed to import NeoPixel libraries. "
                     f"Standard library error: {e}. "
                     f"Pi 5 library error: {e2}. "
-                    f"For Pi 4 and earlier: pip install adafruit-circuitpython-neopixel adafruit-blinka. "
+                    f"For Pi 4 and earlier: pip install adafruit-circuitpython-neopixel 'adafruit-blinka<10'. "
                     f"For Pi 5: pip install Adafruit-Blinka-Raspberry-Pi5-Neopixel"
                 )
                 self._init_error = error_msg

+ 1 - 1
requirements.txt

@@ -21,5 +21,5 @@ lgpio>=0.2.2.0  # Low-level GPIO library (required by rpi-lgpio)
 rpi-lgpio>=0.4  # Provides RPi.GPIO interface, works on Pi 4 and Pi 5
 rpi-ws281x>=5.0.0  # Low-level NeoPixel/WS281x driver (Pi 4)
 adafruit-circuitpython-neopixel>=6.3.0  # Standard NeoPixel library (Pi 4)
-Adafruit-Blinka>=8.0.0  # CircuitPython compatibility layer
+Adafruit-Blinka>=8.0.0,<10  # CircuitPython compatibility layer. <10: Blinka 10 refuses to start unless Python gpiod is >=2.2.2,<3
 Adafruit-Blinka-Raspberry-Pi5-Neopixel>=1.0.0rc1  # Pi 5 PIO-based NeoPixel driver (pre-release)

+ 20 - 0
tests/unit/test_dw_led_controller.py

@@ -0,0 +1,20 @@
+"""DW LED controller: a failing `import board` must surface as _init_error, not raise."""
+import builtins
+
+from modules.led.dw_led_controller import DWLEDController
+
+
+def test_blinka_runtime_error_is_reported_not_raised(monkeypatch):
+    real_import = builtins.__import__
+
+    def fake_import(name, *args, **kwargs):
+        if name == "board":
+            # What Blinka >=10 raises from `import board` when gpiod is out of range
+            raise RuntimeError("Blinka found installed platform dependencies with unsupported versions.")
+        return real_import(name, *args, **kwargs)
+
+    monkeypatch.setattr(builtins, "__import__", fake_import)
+
+    controller = DWLEDController()
+    assert controller._initialize_hardware() is False
+    assert "unsupported versions" in controller._init_error