docker icon indicating copy to clipboard operation
docker copied to clipboard

Build libgpiod Python bindings

Open puddly opened this issue 2 years ago • 1 comments

Rationale: I'm working on a Core PR that detects when the Yellow's CM4 module is unseated, which requires reading a few GPIO pins at runtime in Core. libgpiod and its Python bindings seems to be the best way to do this, since it can be included in the base Home Assistant image and isn't specific to the Pi/CM4.


The libgpiod Alpine package's Python bindings (py3-libgpiod) are built against Alpine's default Python 3.11 package and won't install without pulling in the duplicate Python installation, nor is the resulting C extension placed in our Python's site-packages. I've added a new stage replicating the Alpine APKBUILD to re-compile the bindings against our system Python and copy just the single C extension into the site-packages folder.

A simpler alternative to this PR would be to temporarily install py3-libgpiod and copy the .so from /usr/lib/python3.11/... to /usr/local/lib/python3.11, but I'm not sure if Python C extensions are portable across installs in this way. Anecdotally, this worked for me on the Yellow.

puddly avatar Sep 26 '23 00:09 puddly

Did you consider using the pure Python implementation instead? Since this is not really performance relevant I think it should work fine as well: https://pypi.org/project/gpiod/

The API is slightly different unfortunately. I've moved to that library in the silabs-flasher with this change: https://github.com/agners/silabs-flasher/pull/3/files

agners avatar Oct 03 '23 14:10 agners

Because there hasn't been any activity on this PR for quite some time now, I've decided to close it for being stale.

Feel free to re-open this PR when you are ready to pick up work on it again 👍

../Frenck

frenck avatar Jun 08 '24 15:06 frenck