1
0
mirror of https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git synced 2026-10-25 12:39:18 +03:00
Commit Graph

58 Commits

Author SHA1 Message Date
Vincent Fazio
2e0045486b bindings: python: parse non-tuple Iterable keys
When `chip.request_lines` was modified to allow `Iterable`s instead of
only `tuple`s, the code that checked for duplicate line entries in the
`config` argument was not updated to account for the expanded types.

If the `config` argument had a key that was not a `tuple`, `str`, or
`int`, a `TypeError` would be raised when resolving the line offset.

Refactor the code the resolves IDs to offsets into a separate function
to make the logic a bit clearer and to account for the widened types.

Fixes: 8f62e6c453 ("bindings: python: loosen type requirements in public API")
Closes: https://github.com/brgl/libgpiod/issues/148
Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://lore.kernel.org/r/20250902123905.6491-1-vfazio@gmail.com
[Bartosz: don't pass the only argument by name in the call to
_resolve_config_keys_to_offsets()]
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-09-08 09:31:28 +02:00
Bartosz Golaszewski
bf0d733f4d bindings: python: gpiod v2.3.0
Minor gpiod package release.

Changelog:
- add fileno() for Chip and LineRequest
- relax the verbosity adjustment in build_tests.sh
- fix potential PyDict_Next() crash
- fix tests failing after a kernel fix to gpio-sim
- various documentation fixes
- rework the code treewide to make it conformant with mypy and ruff
  linter recommendations
- fix requesting lines by name with multiple entries
- fix a use-after-free bug in python bindings
- fix passing the event clock property to line requests in python
  bindings
- improve the output of LineSettings.__repr__()
- import gpiod attributes in external module
- specify a tar extract filter for python >= 3.12

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-02-19 13:36:05 +01:00
Bartosz Golaszewski
7ac2650893 bindings: gpiod: reword the docstring for LineRequest.__init__()
Change the docstring for LineRequest.__init__() so that when it appears
in sphinx docs as part of the class description, it won't sound as if
the class was not to be used at all.

Reviewed-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20250211-improve-docs-v4-6-dc56702c2ca8@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-02-17 09:17:56 +01:00
Bartosz Golaszewski
d46e8f67aa bindings: python: doc: describe undocumented members
There are several public members in python bindings that are missing
docstrings. Document them for completeness.

Reviewed-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20250211-improve-docs-v4-5-dc56702c2ca8@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-02-17 09:17:53 +01:00
Bartosz Golaszewski
b1bc6664f6 bindings: python: doc: make code examples appear as such in sphinx
In order for code examples inside docstrings to be interpreted as such
by sphinx, we need to use a double colon ("Example::").

Reviewed-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20250211-improve-docs-v4-4-dc56702c2ca8@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-02-17 09:17:50 +01:00
Bartosz Golaszewski
8aa4d84b6f bindings: python: doc: update the docstring for gpiod.request_lines()
The global request_lines() function was updated to take explicitly typed
arguments instead of just passing *args and **kwargs down to
Chip.request_lines(). However, the doc remained unchanged. Update it now
to reflect the actual function parameters.

Reviewed-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20250211-improve-docs-v4-3-dc56702c2ca8@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-02-17 09:17:48 +01:00
Bartosz Golaszewski
38adbae195 bindings: python: provide fileno() for Chip and LineRequest
Certain polling APIs in the standard library - most notably: the
select() function and the poll class - allow to poll any object that
implements the fileno() method returning the underlying file descriptor
number.

Implement fileno() for Chip and LineRequest which allows users to do:

  rd, _, _ = select([chip/request], [], [], 1)

where rd will contain the actual object passed to select which makes for
easier reading of events afterwards.

Reviewed-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20241211-python-fileno-v2-1-84c642572485@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-12-12 15:35:04 +01:00
Bartosz Golaszewski
6d9133a259 bindings: python: fix license tags
Several files under bindings/python/ have wrong license tags.

In general:
- Makefiles should be covered by GPL
- all python sources under bindings/python/gpiod/ and
  bindings/python/tests/ that are part of importable modules should be
  licensed under LGPL
- executable examples should be licensed under GPL

Reported-by: Vincent Fazio <vfazio@xes-inc.com>
Closes: https://github.com/brgl/libgpiod/issues/110
Acked-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20241127150529.126896-1-brgl@bgdev.pl
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-12-05 13:56:15 +01:00
George Harker
7f12d44b31 bindings: python: fix potential PyDict_Next() crash
PyDict_Next() does not guarantee pos is contiguous, and pypy increments
it past the end of the dict size. Fix reliance on pos for constructing
args for libgpiod call.

Fixes: b7ba732e6a ("treewide: libgpiod v2 implementation")
Signed-off-by: George Harker <george@george-graphics.co.uk>
Link: https://lore.kernel.org/r/20241202171302.51437-1-george@george-graphics.co.uk
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-12-02 20:45:17 +01:00
Bartosz Golaszewski
93613618d2 bindings: python: add .pyi files to EXTRA_DIST
While python sdist and wheels are built separately these days, we still
want to package all the extra files in the regular libgpiod release
tarballs. Add new .pyi files to automake's EXTRA_DIST.

Reviewed-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20241120-drop-distutils-v1-1-7498e8b3babe@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-11-25 10:03:45 +01:00
Bartosz Golaszewski
2ede434e67 bindings: python: build: update makefile after renaming of internal.py
The module is now called _internal.py so update the Makefile. Without
this, we're no longer able to generate the distro tarball.

Fixes: b306ce694a ("bindings: python: make internal a private submodule")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-11-20 14:56:34 +01:00
Vincent Fazio
42308c2df1 bindings: python: selectively use f-strings
Since their inclusion in Python 3.6, f-strings have become the preferred
way to format strings with variable values as they are generally more
readable as the value substitution is in place and doesn't have to be
parsed from the list or arguments to `.format()`.

Where it does not impact readability (when the line is <120 characters),
swap usage of `.format()` to an f-string.

For lines that are not converted, inform the linter to ignore attempts
to upgrade those instances to f-strings [0]

[0]: https://docs.astral.sh/ruff/rules/f-string/

Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20241114145116.2123714-15-vfazio@xes-inc.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-11-19 15:21:01 +01:00
Vincent Fazio
f3444341f4 bindings: python: cast return value of LineRequest.get_values
The `values` argument of `_ext.Request.get_values` uses a preallocated
`list[None]` as a buffer that is populated with `Value`s by the external
module that are then returned from the function.

Use `cast` to inform the type checker it's a `list[Value]` despite how
it's allocated.

Also, as `lines` is typed as an `Iterable`, there is no guarantee it has
a `__len__` method. Instead, use the size of the `offsets` array to
allocate the buffer.

Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20241114145116.2123714-14-vfazio@xes-inc.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-11-19 15:21:01 +01:00
Vincent Fazio
fcddb71b45 bindings: python: convert lines to offsets in LineRequest
Remove `_check_line_name` in favor of a new function, `_line_to_offset`,
that converts a line reference to an offset.

This new function helps narrow types and simplifies the iteration logic
that is used to build objects to interface with `_ext.Request`.

Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20241114145116.2123714-13-vfazio@xes-inc.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-11-19 15:21:01 +01:00
Vincent Fazio
fcb520f9fe bindings: python: fix LineRequest union-attr type errors
Since `LineRequest._req` is typed to be `Optional` and because type
checkers may not be able to infer that an object is not `None` from an
earlier call (such as `_check_released`) it is necessary to inform type
checkers of the state of the object to silence union-attr [0] errors.

Instead of littering the code with "# type: ignore" comments, use casts
to inform type checkers that objects are not `None`.

Using `assert` is another option, however this duplicates the logic in
`_check_released` so is redundant at best and, at worst, is not a safe
replacement as `assert` can be elided in optimized Python environments
and these checks need to be runtime enforced.

[0]: https://mypy.readthedocs.io/en/stable/error_code_list.html#check-that-attribute-exists-in-each-union-item-union-attr

Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20241114145116.2123714-12-vfazio@xes-inc.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-11-19 15:21:01 +01:00
Vincent Fazio
01efd10160 bindings: python: add type hints for LineRequest's internal members
Add type hints for LineRequest's internal members so type checkers can
ensure the code properly constrains to these types and accounts for
scenarios where the values are `None`.

Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20241114145116.2123714-11-vfazio@xes-inc.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-11-19 15:21:01 +01:00
Vincent Fazio
72e51c8a94 bindings: python: fix Chip union-attr type errors
Since `Chip._chip` is typed to be `Optional` and because type checkers
may not be able to infer that an object is not `None` from an earlier
call (such as `_check_closed`) it is necessary to inform type checkers
of the state of the object to silence union-attr [0] errors.

Instead of littering the code with "# type: ignore" comments, use casts
to inform type checkers that objects are not `None`.

Using `assert` is another option, however this duplicates the logic in
`_check_closed` so is redundant at best and, at worst, is not a safe
replacement as `assert` can be elided in optimized Python environments
and these checks need to be runtime enforced.

[0]: https://mypy.readthedocs.io/en/stable/error_code_list.html#check-that-attribute-exists-in-each-union-item-union-attr

Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20241114145116.2123714-10-vfazio@xes-inc.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-11-19 15:21:01 +01:00
Vincent Fazio
1cc8bedab6 bindings: python: add type hints for Chip's internal members
Add type hints for Chip's internal members so type checkers can ensure
the code properly constrains to these types and accounts for scenarios
where the values are `None`.

Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20241114145116.2123714-9-vfazio@xes-inc.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-11-19 15:21:01 +01:00
Vincent Fazio
2a2904082f bindings: python: add type hint for the sec variable in poll_fd
The sec variable can be either a float or None, so type it accordingly
to avoid complaints from type checkers.

Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20241114145116.2123714-8-vfazio@xes-inc.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-11-19 15:21:01 +01:00
Vincent Fazio
498ec6df34 bindings: python: add missing method type hints
Add type hints for all method arguments and return values.

Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20241114145116.2123714-7-vfazio@xes-inc.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-11-19 15:21:01 +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
f5c70ec993 bindings: python: explicitly type gpiod.request_lines
Explicitly define the arguments for `gpiod.request_lines` so there is a
clearer linkage with the underlying `Chip.request_lines` interface.

Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20241114145116.2123714-5-vfazio@xes-inc.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-11-19 15:21:01 +01:00
Vincent Fazio
8f62e6c453 bindings: python: loosen type requirements in public API
Previously, `Chip.request_lines` and `LineRequest.reconfigure_lines`
were typed to accept a config argument that was either an int, a str,
or a tuple[int | str].

This had two downsides, namely:
* The tuple was typed as having only a single element and not a variable
  number of elements. The examples and test suite relied on a variable
  length tuple.
* The tuple type itself was overly restictive. The function
  implementations had no requirement that the value be a tuple, only
  that it was iterable if it was not a str or an int.

Now, these functions accept an Iterable[int | str] instead of tuples to
offer greater flexibility to callers.

This change does not break compatibility for existing users.

Closes: https://github.com/brgl/libgpiod/issues/102
Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20241114145116.2123714-4-vfazio@xes-inc.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-11-19 15:21:01 +01:00
Vincent Fazio
b306ce694a bindings: python: make internal a private submodule
The internal submodule shouldn't be exposed as part of the public
interface, so mark it private following PEP 8 convention [0].

[0]: https://peps.python.org/pep-0008/#public-and-internal-interfaces

Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20241114145116.2123714-3-vfazio@xes-inc.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-11-19 15:21:01 +01:00
Vincent Fazio
7fde8a47f5 bindings: python: clean up imports and exports
Remove unused imports and sort the remainder following isort rules.

Update submodules to use lists for `__all__` for ease of re-exporting
public classes from within gpiod.

Place imports used only for the purposes of type checking behind a
TYPE_CHECKING guard.

Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20241114145116.2123714-2-vfazio@xes-inc.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-11-19 15:21:01 +01:00
Bartosz Golaszewski
746ba66cfd bindings: python: chip: remove unused import
We no longer use the select module directly in chip.py so drop the
unneeded import.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-11-13 12:29:04 +01:00
Vincent Fazio
035ad74fdd bindings: python: import gpiod attributes in external module
Previously, the external module relied on gpiod attributes being present
within `globals()` to construct return values back to the caller.

This assumption required callers of the external module to have imported
the attributes to populate `globals()` for the interface to work.

Having this implicit contract is opaque and prone to causing issues if
imports within gpiod modules ever get reworked.

Now, the external module explicitly imports attributes from gpiod in
order to return values back to the caller.

There should be no concern about circular imports as the external module
should be completely imported by the time callers call into it.

Since Py_gpiod_GetGlobalType is no longer used, it has been replaced
with Py_gpiod_GetModuleAttrString which returns a new PyObject*
reference for the named module and attribute that must be decremented
when no longer in use.

Closes: https://github.com/brgl/libgpiod/issues/101
Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20241008175139.1198980-1-vfazio@xes-inc.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-10-14 16:42:38 +02:00
Bartosz Golaszewski
f6c8c3321d bindings: python: improve LineSettings.__repr__()
Currently, for the output of LineSettings.__repr__() to be eval()able,
the user must have pulled all the relevant definitions from gpiod.line
within the scope where it is used. Modify the output so that all the user
needs is `import gpiod`.

Reported-by: Vincent Fazio <vfazio@gmail.com>
Link: https://lore.kernel.org/r/20240920143203.6377-1-brgl@bgdev.pl
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-09-27 10:09:37 +02: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
Vincent Fazio
7c815ae11f bindings: python: fix Chip.request_lines() typing
The output_values argument was typed as a dict of tuples, however, the
code expects a dict of int|str.

Fixes: 27a69b0bfd ("bindings: python: add the output_values argument to Chip.request_lines()")
Closes: https://github.com/brgl/libgpiod/issues/96
Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://lore.kernel.org/r/20240914183352.16090-1-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-09-16 08:36:37 +02:00
Benjamin Cabé
2f38f92ae2 bindings: python: properly pass event clock settings
Python binding was ignoring event_clock line setting.

Signed-off-by: Benjamin Cabé <kartben@gmail.com>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240731104658.93117-1-brgl@bgdev.pl
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-08-01 09:56:19 +02:00
Iker Pedrosa
c497e29ca1 bindings: python: fix a use-after-free bug
`req_cfg` variable is freed and then used, which would generate an
error. Avoid this problem by freeing when the variable will no longer be
used.

Signed-off-by: Iker Pedrosa <ikerpedrosam@gmail.com>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/3d8b12dd60eec59d4184c0bcc7d575b4eccbc22c.1722250385.git.ikerpedrosam@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-07-31 10:46:36 +02:00
Chuang Zhu
237fd2c059 bindings: python: fix line request by name with multiple entries
When multiple entries are requested using line names in
Chip.request_lines(), only the the last entry is added to
LineRequest._name_map, causing a ValueError when trying to use functions
like LineRequest.set_value() on any former entries.

Move the required variables to the correct scope.

Signed-off-by: Chuang Zhu <git@chuang.cz>
[Bartosz: tweak the commit message]
Co-developed-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240710125719.33655-2-brgl@bgdev.pl
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-07-11 13:25:00 +02:00
Kent Gibson
fd57153ab2 bindings: python: more flexible reconfigure_lines()
The C API requires the configuration passed to reconfigure_lines()
to contain the lines in the same order as they were requested.  This is
problematic for the Python bindings which accepts the configuration in
the form of a dict.  For versions prior to Python 3.6, dicts do not
maintain insertion order, so iterating over the dict emits lines in
unreliable order.

Even with later Python versions, the ordering requirement makes
reconfigure_lines() awkward to use as subsequent configurations may
group line settings quite differently to the request, yet the user must
go out of their way to reproduce the original ordering.
This is a task better performed by the bindings.

Further, while the documentation for reconfigure_lines() states that
None settings values are treated as default values, the current
implementation raises an error when it tries to dereference the None,
thinking it is an actual object.

Similarly, providing default values for lines for which no settings
are provided would allow support for reconfiguring a subset of
requested lines.

Rework reconfigure_lines() to remove the ordering requirement and
construct the configuration provided to the C API in request order.
Populate missing or None line settings with default values to satisfy
the requirements of the C API that all requested lines must be
reconfigured.

Closes: https://github.com/brgl/libgpiod/issues/54
Signed-off-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240626053808.179457-3-warthog618@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-07-08 11:50:20 +02:00
Kent Gibson
6ee321061e bindings: python: correct spelling of repetitions
In another one of those spelling quirks, 'repetitions', which is
indicative of something being repeated, is not a direct extension of
'repeat'.

Correct the spelling of 'repetitions'.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240705021731.43143-1-warthog618@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-07-05 09:40:41 +02:00
Bartosz Golaszewski
db68634b73 bindings: python: gpiod v2.2.0
Minor gpiod package release.

Changelog:
- add a script for generating sdist and wheels
- fix make build
- support casting of line.Value to bool
- test fixes
- fix __repr__() implementations

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-06-18 22:23:31 +02:00
Kent Gibson
5f9152b0ca bindings: python: support casting line.Value to bool
Python types default to being truthy when cast to bool, so casting
line.Value to bool always returns True.

Add a line.Value.__bool__() operator to map the line value to bool as
one would intuitively expect, so ACTIVE is True and INACTIVE is False.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240522004643.96863-3-warthog618@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-05-23 09:51:53 +02:00
Bartosz Golaszewski
6d5d8afc9c bindings: python: fix __repr__() implementations
The __repr__() function should - if possible - return a valid Python
expression that can be used to instantiate a new object when evaluated.

LineSettings.__repr__() is missing comas between arguments. Both Chip and
LineSettings also don't prefix the returned string with 'gpiod.'. Fix
both functions and add more test cases - including actually using the
strings returned by __repr__() to create new objects and compare their
contents.

Reported-by: Robert Thomas <rob.thomas@raspberrypi.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-02-05 09:49:10 +01:00
Bartosz Golaszewski
665f360a26 bindings: python: gpiod v2.1.3
Another small bugfix release addressing an issue with building tests.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-11-09 21:26:53 +01:00
Bartosz Golaszewski
3a0f6a0dd3 bindings: python: gpiod v2.1.2
This is a small bugfix release improving how the C extensions for python
bindings tests are built.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-11-09 21:15:10 +01:00
Bartosz Golaszewski
8c8547bfdd bindings: python: gpiod v2.1.1
This is a small bugfix release of the python bindings fixing how the
homepage on pypi is displayed.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-11-03 20:31:23 +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
Bartosz Golaszewski
b436d05809 bindings: python: replace PyModule_AddObjectRef() with PyModule_AddObject()
PyModule_AddObjectRef() was added in cpython v3.10 while libgpiod claims
to depend on python v3.9. Replace it with an older variant that steals the
reference to the added object on success.

Reported-by: Phil Howard <phil@gadgetoid.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-10-11 10:02:09 +02:00
Bartosz Golaszewski
eb9816ebe0 bindings: python: provide the chip_name property in line_request
Provide a wrapper around gpiod_line_request_get_chip_name() for Python
bindings and update the tests.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-07-21 20:33:39 +02:00
Bartosz Golaszewski
4687bcc4f4 bindings: python: specify the symbols to export explicitly
We're currently unintentionally exporting a bunch of symbols that should
remain local to sub-modules. Use __all__ where appropriate so that we
don't re-export standard library functions such as select() etc. in the
gpiod module.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-05-25 15:30:25 +02:00
Bartosz Golaszewski
a0b8bcee3f bindings: python: change the interpretation of None in event wait
The docs don't mention it but currently passing None as the timeout to
one of the event wait methods works like passing 0 to select() - the wait
method returns immediately. Change it to a more standard behavior - None
makes the method block indefinitely until an event becomes available for
reading.

This is a slight change in the behavior but let's hope nobody complains
as libgpiod v2 is still pretty recent and its adoption is (hopegully)
not wide-spread yet.

Reported-by: Nicolas Frattaroli <frattaroli.nicolas@gmail.com>
Suggested-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
2023-05-24 11:12:49 +02:00
Viresh Kumar
f6308c1307 bindings: fix typo "SPDX-FileCopyrightTest" in copyright headers
It should be SPDX-FileCopyrightText instead. Fix it.

Reported-by: Erik Schilling <erik.schilling@linaro.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Erik Schilling <erik.schilling@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-05-23 11:02:51 +02:00
Bartosz Golaszewski
0929f3990e bindings: python: bump version to v2.0.1
Update the version of python bindings to v2.0.1. I treat it as a bug-fix
release as the changes only apply to packaging and building (in
preparation for making the package available on pypi) and there are no
functional changes in the bindings.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-04-13 09:49:41 +02:00
Bartosz Golaszewski
b503572922 bindings: python: don't store build system paths in output files
Using the __FILE__ macro contaminates the build artifacts with global
build host file system paths. Don't use it.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-02-08 14:24:30 +01:00
Bartosz Golaszewski
27a69b0bfd bindings: python: add the output_values argument to Chip.request_lines()
Add a new optional argument to Chip.request_lines() called output_values.
It accepts a dictionary of mappings between line names or offsets to the
output values the requested lines should be set to at request-time.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-01-25 09:42:02 +01:00