Allen-Synthesis / EuroPi

EuroPi: A reprogrammable Eurorack module based on the Raspberry Pi Pico

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CI fails when using `time` module in `firmware/experimental`

chrisib opened this issue · comments

Bug Report

CI fails when using the time.ticks_ms function (and likely others) inside the firmware/experimental directory, e.g.

2023-10-29T13:21:56.1098053Z =================================== FAILURES ===================================
2023-10-29T13:21:56.1098756Z ______________________________ test_menu_imports _______________________________
2023-10-29T13:21:56.1099260Z 
2023-10-29T13:21:56.1099398Z mock_time_module = None
2023-10-29T13:21:56.1099673Z 
2023-10-29T13:21:56.1099877Z     def test_menu_imports(mock_time_module):
2023-10-29T13:21:56.1100793Z         """User the bootloader code to test that every script declared in EUROPI_SCRIPTS can be imported."""
2023-10-29T13:21:56.1101748Z         bootloader = BootloaderMenu(EUROPI_SCRIPTS)
2023-10-29T13:21:56.1102367Z         for display_name in EUROPI_SCRIPTS.keys():
2023-10-29T13:21:56.1102979Z             class_name = EUROPI_SCRIPTS[display_name]
2023-10-29T13:21:56.1103609Z             clazz = bootloader.get_class_for_name(class_name)
2023-10-29T13:21:56.1104472Z >           assert bootloader._is_europi_script(clazz), f"{class_name} is not a EuroPiScript"
2023-10-29T13:21:56.1105092Z 
2023-10-29T13:21:56.1105292Z software/tests/contrib/test_menu.py:21: 
2023-10-29T13:21:56.1105920Z _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
2023-10-29T13:21:56.1106421Z 
2023-10-29T13:21:56.1106914Z cls = <class 'bootloader.BootloaderMenu'>, c = None
2023-10-29T13:21:56.1107806Z 
2023-10-29T13:21:56.1107950Z     @classmethod
2023-10-29T13:21:56.1108304Z     def _is_europi_script(cls, c):
2023-10-29T13:21:56.1108801Z >       return issubclass(c, EuroPiScript)
2023-10-29T13:21:56.1109396Z E       TypeError: issubclass() arg 1 must be a class
2023-10-29T13:21:56.1109812Z 
2023-10-29T13:21:56.1110030Z software/firmware/bootloader.py:80: TypeError
2023-10-29T13:21:56.1110801Z ----------------------------- Captured stdout call -----------------------------
2023-10-29T13:21:56.1111689Z Warning: Ignoring bad qualified class name: contrib.euclid.EuclideanRhythms
2023-10-29T13:21:56.1112605Z   caused by: module 'time' has no attribute 'ticks_ms'
2023-10-29T13:21:56.1113279Z =========================== short test summary info ============================
2023-10-29T13:21:56.1114262Z FAILED software/tests/contrib/test_menu.py::test_menu_imports - TypeError: is...
2023-10-29T13:21:56.1115181Z =================== 1 failed, 221 passed, 1 skipped in 0.67s ===================
2023-10-29T13:21:56.1384495Z ##[error]Process completed with exit code 1.

See #309 for sample logs

To work-around the issue I had to change import time to import utime in firmware/experimental/screensaver.py. Interestingly, using import utime as time did not resolve the problem.

To Reproduce
Steps to reproduce the behavior:

  1. Create an experimental module in firmware/experimental
  2. Make sure the module uses import time and calls time.ticks_ms() somewhere
  3. Import that experimental module into a contrib script. Make sure the contrib script is in menu.py so the bootloader menu test catches it
  4. Allow CI to run on the modified branch
  5. Check the run_tests/build logs. Check for an error like the one above

Expected behavior
Using the time module shouldn't cause CI to fail like this.

Work around
Using utime instead of time in the experimental directory appears to resolve the CI issues.

At the time of writing, utime and time are aliases, though I believe uPython is deprecating the use of modules with the u prefix in preference of using CPython-style naming.

Additional context
My best guess is that conftest's path manipulation may be at the heard of this? The fact that the firmware/experimental directory puts scripts one level lower than normal may have something to do with it; using time.ticks_ms directly in scripts inside contrib doesn't result in the CI failure. It only seems to happen if the function is called inside the experimental directory.