Conditionally installing libraries? (related to new pi throttling plugin)

I see the pi plugin. Neat. There's a way to get the throttling without needing to shell out a process, but it means installing a library. That install only makes sense on a Pi, obviously. Would we just do it with sys.platform in setup.py?

Or...

import os
os.uname()

sys.platform is already there; I'm more worried about how Gina wants to do it than how it can be done.

1 Like

setup.py only gets executed in source installs. If you create a full build and install that, no setup.py will be run, which makes tricks like that very tricky. Also the reason why I haven't made installation of the pi support plug-in depend on the runtime environment.

Right now all OctoPrint are source installs, but long term that will most likely change.

I want to talk through this more with you, I'll set a reminder for 2wks, which should be when you are done with your vacation.

hey @foosel you're back, right? How do you plan on the Pi plugin being installed? Again, my goal is to keep it from needing subprocess by conditionally installing another package. Certainly we can do what Ansible does by trying to import it and falling back on subprocess.

It's simply bundled (like the OctoPi Support one is now) and only loads if it detects that it's running in a supported environment through the __plugin_load__ callback. I haven't been able to identify a way to make it a conditional dependency to OctoPrint proper that wouldn't break outside of source installs.

In its specific case, the import attempt with fallback approach would be a possibility though. It's similar to how the bundled Discovery plugin only enables ZeroConf support if the required dependency is installed.

Forgot to ask the last time btw: What library would that be? I'd like to take a look at it.

It's now in py-videocore, which is aimed at controlling the entire video core but the magic throttle bit is anyhow. Here's my commit that adds throttling.

Hmmm, might just extract parts of that library and put it in the plugin. Otherwise it has heavy dependencies like numpy.

Ugh numpy... get ready for the complaints during install.

Yeah, that's pretty much a nonstarter.