Tweak Python bindings to create standalone sdist package #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This changeset vendors the gpiod library into the Python package.
This works by symlinking the
lib
andinclude
directories up to the parent module, and updatingMANIFEST.in
to include the source files.If "LINK_SYSTEM_LIBGPIOD =1" is not specified then the
gpiod._ext
C Extension is amended to include all of the C sources forgpiod
, so it can be built as a standalone module without depending upon a shared distro library.Why?
So that it can produce an sdist that is installable irrespective of the availability or version of a distro-supplied libgpiod. This prevents a libgpiod pypi package install balking because the distro libgpiod is outdated or otherwise incompatible. This happens with the currently available libgpiod on pypi.
This also ensures that libgpiod can be installed via pypi into an isolated virtual environment, specified as a dependency for Python packages and allow Python developers to target the newest API version.
Fallback to system libgpiod
Installing from an sdist with a "LINK_SYSTEM_LIBGPIOD=1" environment variable will drop the vendored library in favour of the system, however the system library must be compatible with the bindings.
Building
This package has been tested on Raspberry Pi OS (Debian Bookworm based) and Ubuntu Mantic (Pi 5 ARM64 release).
You'll need:
Then clone this branch:
Configure and build:
Create yourself a venv so you can install Python packages:
Now you can attempt to install the sdist:
Testing
This package should, in theory, work on any platform with Python >= 3.10.0 and GPIO character device support.
To see if you have any supported devices:
The following test script should toggle line 15 1000 times and report how long it took-
import gpiod
or run the below from thelibgpiod/bindings/python
directory.