Arksine / moonraker

Web API Server for Klipper
https://moonraker.readthedocs.io
GNU General Public License v3.0
1.05k stars 404 forks source link

load_system_module constantly fails on system with non-standard path layout #669

Closed MarSoft closed 1 year ago

MarSoft commented 1 year ago

What happened

I use NixOS. It stores Python modules under a unique path starting with /nix/store/. When moonraker wants to load a system module, in particular for GPIO pins (AFAICT it is not used for anything else), it calls load_system_module function. This function runs a loop over SYS_MOD_PATHS declared as glob.glob("/usr/lib/python3*/dist-packages") + glob.glob("/usr/lib/python3*/site-packages") — i.e. looks for packages installed for any Python version. I think this complex logic (instead of just import) is a workaround to look for other Python version's module variant. But on NixOS there is no /usr/lib/python3* and even no /usr/lib directory. So SYS_MOD_PATHS == [] and the loop does not run at all. As a result, even when libgpiod is properly installed and can be just imported, moonraker complains that it was Unable to import module gpiod and hence cannot use GPIO pins.

Client

Fluidd

Browser

Chrome

How to reproduce

  1. Install Moonraker on a system with non-standard filesystem layout
  2. Make sure that gpiod can be imported from plain Python shell
  3. Enable any GPIO pin in Moonraker config
  4. Observe Moonraker unable to import gpiod.

Additional information

Possible fixes:

  1. Append some dummy path like /dev/null to the end of SYS_MOD_PATHS list;
  2. First try to just import the module, and run all that machinery only if simple import fails.
Arksine commented 1 year ago

This should be resolved. Thanks.