1
0
mirror of https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git synced 2026-10-24 00:48:53 +03:00
Commit Graph

29 Commits

Author SHA1 Message Date
Bartosz Golaszewski
31e184a41e bindings: python: use the correct libgpiod API version define in setup.py
Since commit a62c732936 ("core: change the behavior of
gpiod_api_version()"), the libgpiod build expects the
GPIOD_API_VERSION_STR external define to contain the API version string.
The setup.py script in python bindings was not updated so it fails to
build the library sources into the generated wheel. Use the correct
define.

Fixes: a62c732936 ("core: change the behavior of gpiod_api_version()")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-17 09:13:19 +02:00
Vincent Fazio
0c466480e7 bindings: python: setup: use logging module
Use the `logging` module to conform to setuptools' recommendations [0].

[0]: https://setuptools.pypa.io/en/latest/deprecated/distutils-legacy.html#prefer-setuptools

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://patch.msgid.link/20260401001459.19159-5-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-04-03 11:00:36 +02:00
Vincent Fazio
49843b8c70 bindings: python: setup: apply linter recommendations
* Drop unneeded mode parameters
* Cast toml parsing result to dict[str, str] for expected license value
* Disambiguate the `line` variable type for parsing the .asc file

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://patch.msgid.link/20260401001459.19159-4-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-04-03 11:00:36 +02:00
Vincent Fazio
0bb990a59e bindings: python: setup: add type annotations
Add type annotations to help with lint checks.

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://patch.msgid.link/20260401001459.19159-3-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-04-03 11:00:36 +02:00
Vincent Fazio
21d1687b88 bindings: python: copy the license into distributions
Previously, the bindings called out the SPDX license identifier in the
pyproject.toml but did not include a copy of the license in either the
source or binary distributions.

This can be problematic for tools that rely on extracting license
information, such as Buildroot or other license auditing mechanisms.

Now, when distributions are built, the license is copied out of the
libgpiod source tarball and into the target distribution.

Closes: https://github.com/brgl/libgpiod/issues/162
Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://patch.msgid.link/20260228184158.25003-1-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-03-02 12:13:12 +01:00
Bartosz Golaszewski
2838c7604a bindings: python: fix coding style in setup.py
Add a missing newline and make black happy.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-10-13 17:24:07 +02:00
Vincent Fazio
1ee51f95c5 bindings: python: migrate metadata to pyproject.toml
PEP 621 [0] designated pyproject.toml as the standard place to store
project metadata.

Setuptools, the build system used by this project, has support for
reading metadata from this location. As such, migrate the majority of
the metadata out of `setup.py`.

For now, the external modules are left declared in `setup.py` because
support within pyproject.toml is still experimental [1].

New metadata has been added/updated, namely:
  * Add Trove classifiers
  * Add a link to the issues page
  * Update license from LGPL-2.1 to LGPL-2.1+ to match SPDX identifier

[0]: https://peps.python.org/pep-0621/
[1]: https://setuptools.pypa.io/en/stable/userguide/ext_modules.html#pyproject-toml

Closes: https://github.com/brgl/libgpiod/issues/107
Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20241122171027.762311-1-vfazio@xes-inc.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-11-27 11:33:57 +01:00
Vincent Fazio
30e23df2ef bindings: python: add type stub for the _ext module
Add a type stub for the compiled external module so that types and
methods used from the module are accurately type checked.

Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20241114145116.2123714-6-vfazio@xes-inc.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-11-19 15:21:01 +01:00
Vincent Fazio
b66ebbbcf9 bindings: python: specify a tar extract filter
Starting in Python 3.12, extracting files from tarballs without a filter
specified generates a DeprecationWarning [0].

For Python >= 3.12, specify the `fully_trusted_filter` filter which
replicates the behavior from previous versions.

This filter also makes sense as we should be able to trust the tarball
the maintainers generate after the hash has been verified.

[0]: https://docs.python.org/3/library/tarfile.html#tarfile-extraction-filter

Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20241107205001.574426-1-vfazio@xes-inc.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-11-12 13:44:05 +01:00
Vincent Fazio
c840e17a9c bindings: python: add py.typed marker
Per PEP 561 [0], the marker is used by type checkers like mypy
to recognize that the library is typed.

[0]: https://peps.python.org/pep-0561/#packaging-type-information

Closes: https://github.com/brgl/libgpiod/issues/94
Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://lore.kernel.org/r/20240914183302.15768-1-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-09-16 08:42:42 +02:00
Phil Howard
d588a6a592 bindings: python: standalone build tooling for tests
Move extension definitions and tooling for building tests into
`build_tests.py` and update Makefile.am to call it with appropriate path
prefixes.

`build_tests.py` will perform a standalone build of the text extensions,
keeping any build noise in a temporary directory and copying the final
built modules automatically out to `tests/gpiosim` and `tests/procname`.

Add "python-tests-run" to Makefile.am so it's clear how to run the tests.

Add .so object files generated by build_test.py to Makefile.am's
clean-local.

Signed-off-by: Phil Howard <phil@gadgetoid.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-11-08 20:50:02 +01:00
Bartosz Golaszewski
b9cf47accb bindings: python: gpiod v2.1.0
Release libgpiod python bindings v2.1.0.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-11-03 19:34:25 +01:00
Phil Howard
0e81b62c01 bindings: python: optionally include module in sdist
Optionally vendor libgpiod source into sdist so that the Python module can
be built from source, even with a missing or mismatched system libgpiod.

Add two new environment variables "LINK_SYSTEM_LIBGPIOD" and
"LIBGPIOD_VERSION" to control what kind of package setup.py will build.

In order to build an sdist or wheel package with a vendored libgpiod a
version must be specified via the "LIBGPIOD_VERSION" environment variable.

This will instruct setup.py to verify the given version against the list
in sha256sums.asc and ensure it meets or exceeds a LIBGPIOD_MINIMUM_VERSION
required for compatibility with the bindings.

It will then fetch the tarball matching the requested version from
mirrors.edge.kernel.org, verify the sha256 signature, unpack it, and copy
the lib and include directories into the package root so they can be
included in sdist or used to build a binary wheel.

eg: LIBGPIOD_VERSION=2.1.0 python3 setup.py sdist

Will build a source distribution with gpiod version 2.1.0 source included.

It will also save the gpiod version into "libgpiod-version.txt" so that it
can be passed to the build when the sdist is built by pip.

Requiring an explicit version ensures that the Python bindings - which
can be changed and versions independent of libgpiod - are built against a
stable libgpiod release.

In order to force a package with vendored gpiod source to link the system
libgpiod, the "LINK_SYSTEM_LIBGPIOD" environment variable can be used:

eg: LINK_SYSTEM_LIBGPIOD=1 pip install libgpiod

Signed-off-by: Phil Howard <phil@gadgetoid.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-11-03 11:36:28 +01:00
Phil Howard
389a966d4e bindings: python: move long_description into README.md
Move the long_description into README.md and include some basic
information about libgpiod, and some simple Python example code.

Signed-off-by: Phil Howard <phil@gadgetoid.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-10-24 11:06:12 +02:00
Bartosz Golaszewski
1a15d301b9 bindings: python: change the package name to 'gpiod'
We now control the name 'gpiod' on pypi. Let's change the project name
as the package we import in python code is named 'gpiod' and not
'libgpiod'

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-10-24 10:20:21 +02:00
Phil Howard
9f9671dbb6 bindings: python: simplify environ access
Use environ.get() in lieu of an explicit check for GPIOD_WITH_TESTS in
os.environ.

Returns None and evaluates as False if GPIOD_WITH_TESTS == "1" is
not specified.

Signed-off-by: Phil Howard <phil@gadgetoid.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-10-13 10:36:31 +02:00
Phil Howard
07a3265715 bindings: python: require python 3.9.0
Required minimum version for PyModule_AddType helper.

Signed-off-by: Phil Howard <phil@gadgetoid.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-10-12 21:07:11 +02:00
Bartosz Golaszewski
b9f5d29950 bindings: python: don't install test-specific C extension binaries
We want to ship the source code for C extensions used by the test suite
but not install the built shared objects or put them into the bdist.
Extend the build_ext command to delete the tests from the build directory
right after the extensions have been built and - possibly - installed
into the source tree (if --inplace is set).

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-04-18 15:08:57 +02:00
Bartosz Golaszewski
4e75476ccb Revert "bindings: python: fix out-of-tree build"
This reverts commit addf968c73.

We're moving towards being compatible with PEP 517 for building and
currently the following error happens when running setup.py build_py:

running build_py
error: Error: setup script specifies an absolute path:

    <snip>/libgpiod/bindings/python/./gpiod/ext/chip.c

setup() arguments must *always* be /-separated paths relative to the
setup.py directory, *never* absolute paths.

As the Makefile build should only be used for development purposes, I
think we can safely drop support for out-of-tree build. Python bindings
have now been spun out into their own tarball and are available to
install from pip.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-04-18 14:50:33 +02:00
Bartosz Golaszewski
0494604dbe bindings: python: exclude test submodules from the package list
We already exclude 'tests' but 'tests.*' must be excluded as well if we
don't want to install the gpiosim and procname submodules.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-04-17 13:12:54 +02:00
Bartosz Golaszewski
381862780d bindings: python: add a long description to setup.py
Add a long description that will be displayed on the main page once we
make the project available on pypi.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-04-12 21:53:57 +02:00
Bartosz Golaszewski
136553212c bindings: python: exclude tests from the wheel
We currently "include" the gpiod package in find_packages() which does
nothing as it would be discovered anyway. We want to package the test
sources but exclude it from the binary wheel so use the "exclude"
argument.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-04-12 21:51:01 +02:00
Bartosz Golaszewski
d5a454cda5 bindings: python: change the project name to libgpiod
The name 'gpiod' is already taken on pypi. Switch to using 'libgpiod'
as the name of the project. Keep 'gpiod' as the package name which
maintains code compatibility.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-04-12 21:40:56 +02:00
Joerg Faschingbauer
addf968c73 bindings: python: fix out-of-tree build
Makefile.am delegates the build of the python extension to its
setup.py file, which references the extension .c files relative to the
source dir. This makes it impossible to build in a directory that is
different from the source directory (for example, for PC and ARM but
from the same source).

* Invoke setup.py from $(srcdir)
* Modify setup.py to pick up .c files relative from setup.py's own
  directory.

Signed-off-by: Joerg Faschingbauer <jf@faschingbauer.co.at>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-01-18 10:21:18 +01:00
Bartosz Golaszewski
72bce4cd96 bindings: python: tests: set the process name
When we run the test suite by calling the __main__ function of the module,
the name of the process as visible in the system becomes "python". Let's
set it to "python-gpiod" before running the tests. This way gpiosim will
name its configfs attributes appropriately.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2022-12-09 10:06:53 +01:00
Bartosz Golaszewski
324d3c0741 bindings: python: extend setup.py
Add additional information to setup.py. This will be visible in the EGG
file.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2022-12-07 09:54:23 +01:00
Bartosz Golaszewski
366d82545e bindings: python: fix the GPIOD_WITH_TESTS build flag
Currently in order to disable test the variable needs to be explicitly
set to GPIOD_WITH_TESTS= in the environment or setup.py will crash.

Assume tests should not be built if the variable is not set at all.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2022-12-07 09:54:19 +01:00
Bartosz Golaszewski
242d88b7fe bindings: python: decouple the version of the bindings from libgpiod API version
Python bindings now have their own setup.py script and can be built
separately from the rest of the code-base. Let's decouple the python
package version from libgpiod API (but let's keep a module attribute
containing the API version) by introducing a version.py submodule that
can be executed by the setup.py script. This way we have a single
canonical place defining the version number.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2022-12-07 09:54:14 +01:00
Bartosz Golaszewski
b7ba732e6a treewide: libgpiod v2 implementation
This commit is the result of a squash of all the commits created during
the development of libgpiod v2. This is done to preserve bisectability
of the git tree. It contains significant re-writes of the core C library
as well as C++ and python bindings. The tools have been adjusted to work
with the new API but have not undergone significant changes yet.

This commit contains the bulk of the work on libgpiod v2 but the
development continues with more changes planned.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
[Ben: fix format specifier for uint64_t]
Signed-off-by: Ben Hutchings <ben.hutchings@mind.be>
[Viresh: Fix ioctl number for gpiod_line_request_reconfigure_lines()]
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
[Kent: bug fixes, improvements, better pointer contracts, type strictness]
Signed-off-by: Kent Gibson <warthog618@gmail.com>
2022-10-31 11:15:14 +01:00