Tweak Python bindings to create standalone sdist package #2
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 "USE_SYSTEM_GPIOD=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 "USE_SYSTEM_GPIOD=1" environment variable will drop the vendored library in favour of the system, however the system library must be compatible with the bindings.
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:
Next, make sure you've set yourself up a venv, activate it and
pip install --upgrade pip wheel
for a recent build environment, eg:You'll also need to
sudo apt install python3-dev
.Then:
import gpiod
or run the below from thelibgpiod/bindings/python
directory.Finally, the following test script should toggle line 15 1000 times and report how long it took-