bindings: python: more flexible reconfigure_lines()
authorKent Gibson <warthog618@gmail.com>
Wed, 26 Jun 2024 05:38:07 +0000 (13:38 +0800)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Mon, 8 Jul 2024 09:50:20 +0000 (11:50 +0200)
commitfd57153ab2ba0d05f359f21eb72765ac1ede8fb5
tree9413064f6a8b292a07c5207420f2da234164c343
parent40db20eec045b026fb76089fbf46417bae20026b
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>
bindings/python/gpiod/line_request.py