mbox series

[libgpiod,v4,0/1] bindings: python: optionally include module in sdist

Message ID 20231016151848.168209-1-phil@gadgetoid.com
Headers show
Series bindings: python: optionally include module in sdist | expand

Message

Phil Howard Oct. 16, 2023, 3:18 p.m. UTC
This changeset vendors the gpiod library into the Python package.

Why?

So that setup.py 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 when
attempting to install the current libgpiod from pypi onto - for example -
the Debian Bookworm based Raspberry Pi OS or Ubuntu 23.10 Mantic which both
ship with libgpiod v1.6.3.

The availability of a distro agnostic package also ensures that libgpiod
can be installed via pypi into an isolated virtual environment, safely
specified as a dependency for Python packages and allows Python developers
to target the newest API version irrespective of their distro supplied
libgpiod.

This is essential, since a venv is now widely *required* for user Python
projects due to recommendations in pep-688 [1]

For Raspberry Pi this sdist can also be converted into a precompiled wheel
by piwheels [2] which is, by default, added to Raspberry Pi OS as a pip
index.

How?

If "LINK_SYSTEM_LIBGPIOD=1" is not specified and "GPIOD_VERSION_STR" is
supplied then the gpiod._ext C Extension is amended to include all of the C
sources for gpiod, so it can be built as a standalone module without
depending upon a shared distro library.

The gpiod sources are included by copying the "lib" and "include"
directories up to the parent module, and updating "MANIFEST.in" to include
the source files when an sdist is built. Additionally the gpiod version
string is included in "libgpiod-version-str.txt" so that it is available
for source builds.

bindings/python/Makefile.am has been extended so that "make" will now
produce a .tar.gz source distribution in bindings/python/dist which is
suitable for uploading to pypi and can be built and installed by any user
with python3-dev installed.

[1] - https://peps.python.org/pep-0668/
[2] - https://www.piwheels.org/

Changes v3 -> v4
- Check for lack of "GPIOD_VERSION_STR" and revert to original behaviour
- Add status messages to setup.py, hinting at the package build mode

Changes v2 -> v3
- Pass in correct "GPIOD_VERSION_STR" from build
- Output an sdist build for pypi

Changes v1 -> v2
- Switch from symlinks to explicit file copy

Phil Howard (1):
  bindings: python: optionally include module in sdist

 bindings/python/MANIFEST.in |   5 ++
 bindings/python/Makefile.am |   3 +
 bindings/python/setup.py    | 122 +++++++++++++++++++++++++++++++-----
 3 files changed, 114 insertions(+), 16 deletions(-)