qemu-gpiodev/libgpiod.git
2 weeks agocore: allow guse created gpiochip nshubin/guse-fix
Nikita Shubin [Thu, 13 Mar 2025 08:13:13 +0000 (11:13 +0300)]
core: allow guse created gpiochip

Add this to check if device was created via guse and allow it.

Signed-off-by: Nikita Shubin <nikita.shubin@maquefel.me>
4 months agobindings: python: tests: provide and use system.check_kernel_version() master bb/master origin/HEAD origin/master
Bartosz Golaszewski [Wed, 20 Nov 2024 13:18:20 +0000 (14:18 +0100)]
bindings: python: tests: provide and use system.check_kernel_version()

We claim that libgpiod python bindings have no dependencies other than
the python standard library but this is not true - the tests do depend
on deprecated distutils for kernel version parsing.

As distutils is deprecated, the recommended improvement is to use the
Version class from packaging.version but this would too entail pulling
in an external module.

Let's instead implement the kernel version check in C using uname() and
put it into the tests.system extension. This allows us to entirely drop
the distutils import.

Reviewed-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20241120-drop-distutils-v1-3-7498e8b3babe@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
4 months agobindings: python: tests: rename procname to system
Bartosz Golaszewski [Wed, 20 Nov 2024 13:18:19 +0000 (14:18 +0100)]
bindings: python: tests: rename procname to system

We'll be extending the functionality of that C extension with other
OS-level helpers so change its name to 'system'.

Reviewed-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20241120-drop-distutils-v1-2-7498e8b3babe@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
4 months agobindings: python: add .pyi files to EXTRA_DIST
Bartosz Golaszewski [Wed, 20 Nov 2024 13:18:18 +0000 (14:18 +0100)]
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>
4 months agobindings: python: build: update makefile after renaming of internal.py
Bartosz Golaszewski [Wed, 20 Nov 2024 13:56:34 +0000 (14:56 +0100)]
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: b306ce694ab1 ("bindings: python: make internal a private submodule")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
4 months agobindings: python: configure and document dev dependencies
Vincent Fazio [Thu, 14 Nov 2024 14:51:16 +0000 (08:51 -0600)]
bindings: python: configure and document dev dependencies

Mypy [0] is a popular static type checker that validates attribute and
variable use and ensures function arguments adhere to type annotations.

Ruff [1] is a popular Rust-based Python linter and code formatter. It
has support for a large set of linting rules [2] and largely complies
with the Black format [3].

Add documentation to README.md for how to run the tools.

[0]: https://mypy.readthedocs.io/en/stable/
[1]: https://docs.astral.sh/ruff/
[2]: https://docs.astral.sh/ruff/rules/
[3]: https://docs.astral.sh/ruff/formatter/#black-compatibility

Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20241114145116.2123714-24-vfazio@xes-inc.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
4 months agobindings: python: tests: selectively use f-strings
Vincent Fazio [Thu, 14 Nov 2024 14:51:15 +0000 (08:51 -0600)]
bindings: python: tests: 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-23-vfazio@xes-inc.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
4 months agobindings: python: tests: ignore purposeful type errors
Vincent Fazio [Thu, 14 Nov 2024 14:51:14 +0000 (08:51 -0600)]
bindings: python: tests: ignore purposeful type errors

Some of the unit tests intentionally call methods or assign properties
with invalid values to ensure they fail in an expected way.

Type checkers complain for these instances so inform them via directive
that these lines should be ignore for specific errors.

Additionally, some lines that access properties without assigning the
value look like they perform no action to linters.

To appease the linter, read the value into a throw-away variable.

Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20241114145116.2123714-22-vfazio@xes-inc.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
4 months agobindings: python: tests: add type hints to internal members
Vincent Fazio [Thu, 14 Nov 2024 14:51:13 +0000 (08:51 -0600)]
bindings: python: tests: add type hints to internal members

Add type hints for internal members of the test cases so type checkers
can ensure the code properly constrains to these types and accounts for
scenarios where the values are `None`.

In most cases, the type checker is allowed to assume the inferred type
upon assignment.

An example is any test case that creates a `Chip` as part of its `setUp`
method. Many of these tests subsequently set the reference to `None` in
`tearDown` to free up resources to be collected by the GC.

If the member was "properly" typed to be `Optional`, all references in
the unit tests would need to be guarded by an assert or a cast or
ignored by the type checker. This is noisy and doesn't add value since
for the life of the test it should always be a valid reference.

Instead, allow `tearDown` to violate the inferred type and inform the
type checker to ignore the assignment via directive.

If the tests are ever changed to set the member to something other than
the inferred type outside of `tearDown`, explicit type hints and proper
checks should be added.

Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20241114145116.2123714-21-vfazio@xes-inc.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
4 months agobindings: python: tests: add missing method type hints
Vincent Fazio [Thu, 14 Nov 2024 14:51:12 +0000 (08:51 -0600)]
bindings: python: tests: 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-20-vfazio@xes-inc.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
4 months agobindings: python: tests: add type stubs for external modules
Vincent Fazio [Thu, 14 Nov 2024 14:51:11 +0000 (08:51 -0600)]
bindings: python: tests: add type stubs for external modules

Add type stubs for the compiled external modules so that types and
methods used from the modules are accurately type checked.

Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20241114145116.2123714-19-vfazio@xes-inc.com
[Bartosz: add missing SPDX license and copyright tags]
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
4 months agobindings: python: tests: make EventType private to prevent export
Vincent Fazio [Thu, 14 Nov 2024 14:51:10 +0000 (08:51 -0600)]
bindings: python: tests: make EventType private to prevent export

Previously, both tests_edge_event and tests_info_event had a public
module level EventType member.

The __main__ module for unittests does a star import from both modules
which led to an import conflict between the two.

It is not necessary to import EventType to run unit tests.

Now, EventType is private to avoid being imported via star syntax.

Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20241114145116.2123714-18-vfazio@xes-inc.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
4 months agobindings: python: tests: clean up imports and exports
Vincent Fazio [Thu, 14 Nov 2024 14:51:09 +0000 (08:51 -0600)]
bindings: python: tests: clean up imports and exports

Remove unused imports and sort the remainder following isort rules.

Update the submodules to use `__all__` to advertise available imports.

Remove an unnecessary blank line in the VersionString class to abide by
the ruff formatter's rules (compatible with black's formatting).

Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20241114145116.2123714-17-vfazio@xes-inc.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
4 months agobindings: python: tests: fix duplicate test name
Vincent Fazio [Thu, 14 Nov 2024 14:51:08 +0000 (08:51 -0600)]
bindings: python: tests: fix duplicate test name

Previously, the `test_rising_edge_event` test was defined twice.

The second instance of the test actually tested the falling edge event
and was shadowing the first test which tested the rising edge event.

Now, the second instance is renamed to `test_falling_edge_event` to
reflect what it is testing and to avoid the naming conflict.

Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20241114145116.2123714-16-vfazio@xes-inc.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
4 months agobindings: python: selectively use f-strings
Vincent Fazio [Thu, 14 Nov 2024 14:51:07 +0000 (08:51 -0600)]
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>
4 months agobindings: python: cast return value of LineRequest.get_values
Vincent Fazio [Thu, 14 Nov 2024 14:51:06 +0000 (08:51 -0600)]
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>
4 months agobindings: python: convert lines to offsets in LineRequest
Vincent Fazio [Thu, 14 Nov 2024 14:51:05 +0000 (08:51 -0600)]
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>
4 months agobindings: python: fix LineRequest union-attr type errors
Vincent Fazio [Thu, 14 Nov 2024 14:51:04 +0000 (08:51 -0600)]
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>
4 months agobindings: python: add type hints for LineRequest's internal members
Vincent Fazio [Thu, 14 Nov 2024 14:51:03 +0000 (08:51 -0600)]
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>
4 months agobindings: python: fix Chip union-attr type errors
Vincent Fazio [Thu, 14 Nov 2024 14:51:02 +0000 (08:51 -0600)]
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>
4 months agobindings: python: add type hints for Chip's internal members
Vincent Fazio [Thu, 14 Nov 2024 14:51:01 +0000 (08:51 -0600)]
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>
4 months agobindings: python: add type hint for the sec variable in poll_fd
Vincent Fazio [Thu, 14 Nov 2024 14:51:00 +0000 (08:51 -0600)]
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>
4 months agobindings: python: add missing method type hints
Vincent Fazio [Thu, 14 Nov 2024 14:50:59 +0000 (08:50 -0600)]
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>
4 months agobindings: python: add type stub for the _ext module
Vincent Fazio [Thu, 14 Nov 2024 14:50:58 +0000 (08:50 -0600)]
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>
4 months agobindings: python: explicitly type gpiod.request_lines
Vincent Fazio [Thu, 14 Nov 2024 14:50:57 +0000 (08:50 -0600)]
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>
4 months agobindings: python: loosen type requirements in public API
Vincent Fazio [Thu, 14 Nov 2024 14:50:56 +0000 (08:50 -0600)]
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>
4 months agobindings: python: make internal a private submodule
Vincent Fazio [Thu, 14 Nov 2024 14:50:55 +0000 (08:50 -0600)]
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>
4 months agobindings: python: clean up imports and exports
Vincent Fazio [Thu, 14 Nov 2024 14:50:54 +0000 (08:50 -0600)]
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>
4 months agobindings: python: chip: remove unused import
Bartosz Golaszewski [Wed, 13 Nov 2024 11:29:04 +0000 (12:29 +0100)]
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>
4 months agobindings: python: generate CPython 3.13 wheels
Vincent Fazio [Wed, 6 Nov 2024 14:22:48 +0000 (08:22 -0600)]
bindings: python: generate CPython 3.13 wheels

Support for CPython 3.13 was added to cibuildwheel in 2.21.3 and
advertised by build in 1.2.2.post1.

Update the dependencies used by generate_pypi_artifacts.sh so CPython
3.13 wheels are now generated.

Closes: https://github.com/brgl/libgpiod/issues/106
Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20241106142248.305219-1-vfazio@xes-inc.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
4 months agobindings: python: specify a tar extract filter
Vincent Fazio [Thu, 7 Nov 2024 20:50:01 +0000 (14:50 -0600)]
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>
5 months agolibgpiod: start v2.3 development cycle
Bartosz Golaszewski [Tue, 22 Oct 2024 10:59:22 +0000 (12:59 +0200)]
libgpiod: start v2.3 development cycle

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
5 months agolibgpiod v2.2 origin/v2.2.x
Bartosz Golaszewski [Tue, 22 Oct 2024 08:18:48 +0000 (10:18 +0200)]
libgpiod v2.2

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
5 months agobindings: glib: tests: fix version regex
Bartosz Golaszewski [Tue, 22 Oct 2024 08:56:02 +0000 (10:56 +0200)]
bindings: glib: tests: fix version regex

Bring the version matching regex pattern in line with the others in the
tree so that it can also match a string without -rcX or -devel suffix.

Fixes: e090088c21b7 ("bindings: add GLib bindings")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
5 months agodbus: data: fix SPDX license identifier in D-Bus config file
Bartosz Golaszewski [Tue, 15 Oct 2024 18:37:13 +0000 (20:37 +0200)]
dbus: data: fix SPDX license identifier in D-Bus config file

Remove the .txt file extension from the license identifier as it got
there by mistake and makes `reuse lint` complain.

Fixes: a5ab76da1e0a ("dbus: add the D-Bus daemon, command-line client and tests")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
5 months agolibgpiod v2.2-rc3
Bartosz Golaszewski [Tue, 15 Oct 2024 13:58:46 +0000 (15:58 +0200)]
libgpiod v2.2-rc3

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
5 months agobindings: python: import gpiod attributes in external module
Vincent Fazio [Tue, 8 Oct 2024 17:51:39 +0000 (12:51 -0500)]
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>
5 months agodbus: display D-Bus API versions implemented by the manager and gpiocli
Bartosz Golaszewski [Mon, 14 Oct 2024 13:13:28 +0000 (15:13 +0200)]
dbus: display D-Bus API versions implemented by the manager and gpiocli

When passing -v/--version to gpiocli or gpio-manager, it's useful to
also know the version of the GPIO D-Bus API the program implements.
Define the version in the gpiodbus.h header and print it together with
the library version.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
5 months agodbus: client: monitor: free the line list at exit
Bartosz Golaszewski [Mon, 7 Oct 2024 19:30:24 +0000 (21:30 +0200)]
dbus: client: monitor: free the line list at exit

Free the list of line proxies stored for the duration of the program at
exit to fix a memory leak.

Note: these objects need to be kept alive for D-Bus events to work.

Fixes: a5ab76da1e0a ("dbus: add the D-Bus daemon, command-line client and tests")
Link: https://lore.kernel.org/r/20241007-dbus-memory-fixes-v1-3-0d56d1aa032d@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
5 months agodbus: client: notify: free chip and line lists at exit
Bartosz Golaszewski [Mon, 7 Oct 2024 19:30:23 +0000 (21:30 +0200)]
dbus: client: notify: free chip and line lists at exit

We don't free the lists storing line and chip objects for the duration
of the program when exiting. Fix it.

Note: these objects need to be kept alive for D-Bus events to work.

Fixes: a5ab76da1e0a ("dbus: add the D-Bus daemon, command-line client and tests")
Link: https://lore.kernel.org/r/20241007-dbus-memory-fixes-v1-2-0d56d1aa032d@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
5 months agodbus: client: notify: fix reference counting
Bartosz Golaszewski [Mon, 7 Oct 2024 19:30:22 +0000 (21:30 +0200)]
dbus: client: notify: fix reference counting

There's a reference overflow when adding chips to the global list and an
underflow when fetching existing chips from that list in connect_line().
Fix both issues.

Fixes: a5ab76da1e0a ("dbus: add the D-Bus daemon, command-line client and tests")
Link: https://lore.kernel.org/r/20241007-dbus-memory-fixes-v1-1-0d56d1aa032d@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
5 months agobuild: add an additional check for glib-mkenums
Bartosz Golaszewski [Fri, 4 Oct 2024 09:25:33 +0000 (11:25 +0200)]
build: add an additional check for glib-mkenums

Some distros split glib-mkenums and other GLib build utilities into a
separate package but the glib-2.0 pkgconfig file pointing to it is
typically shipped as part of the -dev package. This can lead to a
situation where configure thinks it knows where glib-mkenums is but make
then fails because it's not really installed on the system. Check the
existence of the actual executable in addition to querying pkgconfig.

Link: https://lore.kernel.org/r/20241004092533.34368-1-brgl@bgdev.pl
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
5 months agobuild: drop obsolete autoconf macro
Bartosz Golaszewski [Thu, 3 Oct 2024 13:58:06 +0000 (15:58 +0200)]
build: drop obsolete autoconf macro

AC_HEADER_STDC is deprecated and should be replaced with
AC_CHECK_INCLUDES_DEFAULT. We haven't done this until now because the
latter is only available since autoconf v2.71. We kept supporting v2.69
for the sake of Debian stable but it has since upgraded to autoconf v2.71
so we update configure.ac as well and fix an autoconf warning.

Link: https://lore.kernel.org/r/20241003135806.41934-1-brgl@bgdev.pl
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
5 months agotools: line wrap period help
Kent Gibson [Thu, 3 Oct 2024 02:07:43 +0000 (10:07 +0800)]
tools: line wrap period help

The help for periods is overly long so wrap it to make it more
consistent with other help lines.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20241003020743.27194-1-warthog618@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
5 months agolibgpiod v2.2-rc2
Bartosz Golaszewski [Wed, 2 Oct 2024 15:44:34 +0000 (17:44 +0200)]
libgpiod v2.2-rc2

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
5 months agodbus: include data and test files in dist tarballs
Bartosz Golaszewski [Wed, 2 Oct 2024 15:39:21 +0000 (17:39 +0200)]
dbus: include data and test files in dist tarballs

Several data and test files were not included in distro tarballs so add
"dist_" automake variable prefixes where required.

Fixes: a5ab76da1e0a ("dbus: add the D-Bus daemon, command-line client and tests")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
5 months agobindings: python: add misc build files to EXTRA_DIST
Bartosz Golaszewski [Wed, 2 Oct 2024 14:52:01 +0000 (16:52 +0200)]
bindings: python: add misc build files to EXTRA_DIST

Several files are not being included in distro tarballs so the
functionality of the python build is limited compared to the repo. Add
them to EXTRA_DIST.

Fixes: d588a6a5928a ("bindings: python: standalone build tooling for tests")
Fixes: 72d2fa01a2c1 ("bindings: python: add script to generate sdist and wheels")
Fixes: 85089d0e40ac ("bindings: python: add pyproject.toml, pep 518")
Fixes: 389a966d4e61 ("bindings: python: move long_description into README.md")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
5 months agolibgpiod v2.2-rc1
Bartosz Golaszewski [Wed, 2 Oct 2024 10:01:13 +0000 (12:01 +0200)]
libgpiod v2.2-rc1

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
5 months agoNEWS: updates for v2.2
Bartosz Golaszewski [Wed, 2 Oct 2024 10:00:21 +0000 (12:00 +0200)]
NEWS: updates for v2.2

Add release notes for libgpiod v2.2.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
5 months agodbus: client: fix format specifiers for 64-bit types
Bartosz Golaszewski [Tue, 1 Oct 2024 14:34:32 +0000 (16:34 +0200)]
dbus: client: fix format specifiers for 64-bit types

Use G_GUINT64_FORMAT whenever printing 64-bit types to avoid format
specifier warnings.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
5 months agodbus: use correct types for edge events
Bartosz Golaszewski [Tue, 1 Oct 2024 12:54:17 +0000 (14:54 +0200)]
dbus: use correct types for edge events

On 32-bit architectures the size of a gulong will typically be 4 bytes
while we try to package an 8-byte integer when creating the edge event
variant. The client also expects wrong types and crashes. Use strict
type sizes for sending the events.

Closes: https://github.com/brgl/libgpiod/issues/103
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
6 months agobindings: python: improve LineSettings.__repr__()
Bartosz Golaszewski [Fri, 20 Sep 2024 14:32:03 +0000 (16:32 +0200)]
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>
6 months agobindings: python: examples: add graceful exit to async_watch_line_value
Kent Gibson [Tue, 17 Sep 2024 12:54:55 +0000 (20:54 +0800)]
bindings: python: examples: add graceful exit to async_watch_line_value

The purpose of the example is demonstrate using a request with poll().
It provides a hint as to how the poll can be combined with other fds but,
as Python comes with batteries included, the Python version of the example
can be readily extended to actually demonstrate this, as well as how it
can be used in multi-threaded environments.

Extend the example to use an eventfd to allow the poll() to be run in
a background thread and be gracefully terminated by the main thread.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240917125455.324551-1-warthog618@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
6 months agobindings: python: add py.typed marker
Vincent Fazio [Sat, 14 Sep 2024 18:33:02 +0000 (13:33 -0500)]
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>
6 months agobindings: python: fix Chip.request_lines() typing
Vincent Fazio [Sat, 14 Sep 2024 18:33:52 +0000 (13:33 -0500)]
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: 27a69b0bfd4b ("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>
6 months agodbus: update glib dependency to 2.80
Kent Gibson [Wed, 4 Sep 2024 12:50:14 +0000 (20:50 +0800)]
dbus: update glib dependency to 2.80

The gpio-manager makes use of g_log_writer_default_set_debug_domains()
which was added in glib 2.80, but the dependency in configure.ac is only
glib 2.54. This results in compile errors when built with glib between 2.54
and 2.80.

Update the glib dependency, and related dependencies, to 2.80.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240904125014.262715-1-warthog618@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
6 months agobuild: imply --enable-bindings-glib for --enable-dbus
Bartosz Golaszewski [Wed, 4 Sep 2024 14:01:27 +0000 (16:01 +0200)]
build: imply --enable-bindings-glib for --enable-dbus

GLib bindings are required to build the D-Bus daemon. Enable them
automatically if --enable-dbus is passed to configure.

Fixes: a5ab76da1e0a ("dbus: add the D-Bus daemon, command-line client and tests")
Reported-by: Douglas Silva <doug.hs@proton.me>
Suggested-by: Kent Gibson <warthog618@gmail.com>
Tested-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240904140127.58667-1-brgl@bgdev.pl
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
6 months agobuild: fix HAS_GI_DOCGEN never defined error
Kent Gibson [Sat, 31 Aug 2024 07:52:12 +0000 (15:52 +0800)]
build: fix HAS_GI_DOCGEN never defined error

When building without --enable-bindings-glib configure reports this error:

  ...
  checking for help2man... true
  checking that generated files are newer than configure... done
  configure: error: conditional "HAS_GI_DOCGEN" was never defined.
  Usually this means the macro was only invoked conditionally.
  make: *** [Makefile:440: config.status] Error 1

Move the initialization of HAS_GI_DOCGEN outside the conditional
with_bindings_glib section so it is always initialized.

Fixes: e090088c21b7 ("bindings: add GLib bindings")
Signed-off-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240831075212.147812-1-warthog618@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
7 months agotests: don't use g_value_set_static_string() for non-static strings
Bartosz Golaszewski [Tue, 13 Aug 2024 09:30:25 +0000 (11:30 +0200)]
tests: don't use g_value_set_static_string() for non-static strings

As pointed out by Philip Withnall, g_value_set_static_string() must only
be used with actual static strings and not with ones whose life-time is
tied to that of their owner. Use g_value_set_string() to get the gpiosim
properties and rework the existing getter functions returning const
gchar * to return the address provided by libgpiosim directly instead of
passing through the GObject property path.

Suggested-by: Philip Withnall <philip@tecnocode.co.uk>
Link: https://lore.kernel.org/r/20240813093025.94980-1-brgl@bgdev.pl
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
7 months agodbus: add the D-Bus daemon, command-line client and tests
Bartosz Golaszewski [Mon, 12 Aug 2024 08:22:25 +0000 (10:22 +0200)]
dbus: add the D-Bus daemon, command-line client and tests

Add the D-Bus API definition and its implementation in the form of a GPIO
manager daemon and a companion command-line client as well as some
additional configuration and data files (systemd service, example udev
configuration, etc.) and test suites.

Tested-by: Alexander Sverdlin <alexander.sverdlin@siemens.com>
Link: https://lore.kernel.org/r/20240812-dbus-v5-4-ead288509217@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
7 months agobindings: add GLib bindings
Bartosz Golaszewski [Mon, 12 Aug 2024 08:22:24 +0000 (10:22 +0200)]
bindings: add GLib bindings

Implement GObject-based GLib bindings for libgpiod. Include generating
GObject introspection data, tests and examples.

Tested-by: Alexander Sverdlin <alexander.sverdlin@siemens.com>
Link: https://lore.kernel.org/r/20240812-dbus-v5-3-ead288509217@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
7 months agotests: split out the common test code for bash scripts
Bartosz Golaszewski [Mon, 12 Aug 2024 08:22:23 +0000 (10:22 +0200)]
tests: split out the common test code for bash scripts

In order to allow the upcoming DBus command-line client tests to reuse the
existing bash test harness, let's put the common code into an importable
file and rename run_tool to run_prog to reflect that it now can run any
program.

Tested-by: Alexander Sverdlin <alexander.sverdlin@siemens.com>
Link: https://lore.kernel.org/r/20240812-dbus-v5-2-ead288509217@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
7 months agotests: split out reusable test code into a local static library
Bartosz Golaszewski [Mon, 12 Aug 2024 08:22:22 +0000 (10:22 +0200)]
tests: split out reusable test code into a local static library

In order to allow the upcoming GLib and DBus bindings to reuse the test
code, let's put all common elements into reusable libtool objects and
export the relevant symbols in internal headers.

Tested-by: Alexander Sverdlin <alexander.sverdlin@siemens.com>
Link: https://lore.kernel.org/r/20240812-dbus-v5-1-ead288509217@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
7 months agocore: fix coding style
Bartosz Golaszewski [Thu, 1 Aug 2024 09:06:01 +0000 (11:06 +0200)]
core: fix coding style

Add spaces before and after '+' in array size definitions.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
7 months agobindings: python: tests: fix coding style
Bartosz Golaszewski [Thu, 1 Aug 2024 08:26:51 +0000 (10:26 +0200)]
bindings: python: tests: fix coding style

Use black to make the coding style of the line-request test cases
consistent with the rest of the codebase.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
7 months agosphinx: fix coding style
Bartosz Golaszewski [Thu, 1 Aug 2024 08:01:38 +0000 (10:01 +0200)]
sphinx: fix coding style

Use black to automatically correct the coding style of the sphinx
config file.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
7 months agobindings: python: tests: check that event clock is property set in request
Bartosz Golaszewski [Wed, 31 Jul 2024 10:46:58 +0000 (12:46 +0200)]
bindings: python: tests: check that event clock is property set in request

We currently only have a test-case that checks if the event clock
property is correctly set in the LineSettings object but not whether it
is actually passed to the line request. Extend the existing test-case for
line requests to account for event clocks as well.

Link: https://lore.kernel.org/r/20240731104658.93117-2-brgl@bgdev.pl
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
7 months agobindings: python: properly pass event clock settings
Benjamin Cabé [Wed, 31 Jul 2024 10:46:57 +0000 (12:46 +0200)]
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>
8 months agotools: fix a memory leak
Iker Pedrosa [Mon, 29 Jul 2024 10:57:19 +0000 (12:57 +0200)]
tools: fix a memory leak

`info` variable is allocated, but never freed when the loop continues.
Free it so that it isn't leaked.

Signed-off-by: Iker Pedrosa <ikerpedrosam@gmail.com>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/418b4fa7b6279b15ea10936d65ce45e01675e491.1722250385.git.ikerpedrosam@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
8 months agocore: fix chip-info strings termination
Iker Pedrosa [Mon, 29 Jul 2024 10:57:18 +0000 (12:57 +0200)]
core: fix chip-info strings termination

strncpy() truncates the destination buffer if it isn't large enough to
hold the copy. Thus, let's increase the size of the destination strings
to add the NULL character at the end.

Signed-off-by: Iker Pedrosa <ikerpedrosam@gmail.com>
Link: https://lore.kernel.org/r/1d7cf79edf75ef77baa56091852be90e2359e572.1722250385.git.ikerpedrosam@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
8 months agocore: fix line-info strings termination
Iker Pedrosa [Mon, 29 Jul 2024 10:57:17 +0000 (12:57 +0200)]
core: fix line-info strings termination

strncpy() truncates the destination buffer if it isn't large enough to
hold the copy. Thus, let's increase the size of the destination strings
to add the NULL character at the end.

Signed-off-by: Iker Pedrosa <ikerpedrosam@gmail.com>
Link: https://lore.kernel.org/r/84db7bbe2c84b2d880052a05f8b1cc123d60c2dc.1722250385.git.ikerpedrosam@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
8 months agobindings: python: fix a use-after-free bug
Iker Pedrosa [Mon, 29 Jul 2024 10:57:16 +0000 (12:57 +0200)]
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>
8 months agobindings: python: tests: add a new test case
Chuang Zhu [Wed, 10 Jul 2024 12:57:19 +0000 (14:57 +0200)]
bindings: python: tests: add a new test case

Add a test-case for line request by name with multiple entries.

Signed-off-by: Chuang Zhu <git@chuang.cz>
[Bartosz:
  - tweak the commit message
  - improve the test class name
  - extend the test assertion to test the 'baz' line too]
Co-developed-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240710125719.33655-3-brgl@bgdev.pl
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
8 months agobindings: python: fix line request by name with multiple entries
Chuang Zhu [Wed, 10 Jul 2024 12:57:18 +0000 (14:57 +0200)]
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>
8 months agobindings: rust: tests: set direction when reconfiguring lines
Bartosz Golaszewski [Mon, 8 Jul 2024 09:48:58 +0000 (11:48 +0200)]
bindings: rust: tests: set direction when reconfiguring lines

Linux kernel commit b44039638741 ("gpiolib: cdev: Ignore reconfiguration
without direction") made the direction setting mandatory for line config
passed to the kernel when reconfiguring requested lines. Fix the Rust
test cases which don't do it and now fail due to the rest of the
settings being ignored.

Reviewed-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240708094858.85015-1-brgl@bgdev.pl
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
8 months agobindings: cxx: tests: set direction when reconfiguring lines
Bartosz Golaszewski [Mon, 8 Jul 2024 09:48:27 +0000 (11:48 +0200)]
bindings: cxx: tests: set direction when reconfiguring lines

Linux kernel commit b44039638741 ("gpiolib: cdev: Ignore reconfiguration
without direction") made the direction setting mandatory for line config
passed to the kernel when reconfiguring requested lines. Fix the C++ test
case which doesn't do it and now fails due to the rest of the settings
being ignored.

Reviewed-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240708094827.84986-1-brgl@bgdev.pl
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
8 months agobindings: python: tests: add coverage of kernel reconfigure as-is behaviour
Kent Gibson [Wed, 26 Jun 2024 05:38:08 +0000 (13:38 +0800)]
bindings: python: tests: add coverage of kernel reconfigure as-is behaviour

The kernel's handling of reconfigure with default values, as is the
case for providing a None value as the settings to the Python bindings'
reconfigure_lines(), resets any flags set to non-default values when the
line is requested to their default values.  While the flags are cleared,
the kernel makes no corresponding change to the electrical settings -
though subsequent calls to get and set values will apply the updated
flags.

The tests for missing or None settings are extended to demonstrate the
issue for active_low and drive flags, though the issue applies to all
flags.

The tests fail unless the kernel is patched to ignore reconfiguration
of lines without direction set.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240626053808.179457-4-warthog618@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
8 months agobindings: python: more flexible reconfigure_lines()
Kent Gibson [Wed, 26 Jun 2024 05:38:07 +0000 (13:38 +0800)]
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>
8 months agobindings: python: tests: extend reconfiguration tests
Kent Gibson [Wed, 26 Jun 2024 05:38:06 +0000 (13:38 +0800)]
bindings: python: tests: extend reconfiguration tests

A number of the corner cases for reconfiguration are untested, including
 - using None for default settings
 - missing settings for some lines
 - jumbled line ordering relative to the request
 - extra settings for non-requested lines

Add tests for these corner cases.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240626053808.179457-2-warthog618@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
8 months agoREADME: list the development packages required to build the library
Bartosz Golaszewski [Fri, 5 Jul 2024 07:33:14 +0000 (09:33 +0200)]
README: list the development packages required to build the library

The error messages emitted by configure when either libtool, pkg-config
or autoconf-archive packages are missing on the host are not very clear
and seem to cause confusion among users building the project from
sources. List the required packages in the README.

Reviewed-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240705073314.5728-1-brgl@bgdev.pl
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
8 months agodoc: fix sphinx config for rtd
Kent Gibson [Fri, 5 Jul 2024 02:17:50 +0000 (10:17 +0800)]
doc: fix sphinx config for rtd

Generating the latest documentation on readthedocs is broken as the
index.html generated by Doxygen is now being overwritten by one
generated by Sphinx.

Make Sphinx generate a differently named root page that does not
conflict with the index.html generated by Doxygen.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240705021750.43197-1-warthog618@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
8 months agobindings: python: correct spelling of repetitions
Kent Gibson [Fri, 5 Jul 2024 02:17:31 +0000 (10:17 +0800)]
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>
9 months agobindings: python: gpiod v2.2.0
Bartosz Golaszewski [Tue, 18 Jun 2024 20:23:31 +0000 (22:23 +0200)]
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>
9 months agoREADME: add mentions on shellcheck and reuse
Bartosz Golaszewski [Thu, 13 Jun 2024 14:01:17 +0000 (16:01 +0200)]
README: add mentions on shellcheck and reuse

Extend the "Contributing" section of the README to include mentions of
shell scripts having to pass the `shellcheck` test and the entire tree
having to conform to `reuse lint` requirements.

Link: https://lore.kernel.org/r/20240613140117.39048-1-brgl@bgdev.pl
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
9 months agobindings: python: add script to generate sdist and wheels
Vincent Fazio [Tue, 11 Jun 2024 20:50:41 +0000 (15:50 -0500)]
bindings: python: add script to generate sdist and wheels

Introduce a shell script that generates an sdist tarball and PEP 600/656
conformant wheels.

The wheels are generated via cibuildwheel, a tool provided by the Python
Packaging Authority (PyPA) [0]. The tool leverages toolchains within
containers maintained by PyPA [1] to generate wheels that are runnable
on hosts that meet the platform compatibility tag [2] requirements.

By default, the script creates X86_64 and AArch64 CPython 3.9-3.12
wheels for glibc and musl libc based systems.

These defaults can be overridden via CIBW_* environment variables [3].

[0]: https://cibuildwheel.pypa.io/en/stable/
[1]: https://github.com/pypa/manylinux/
[2]: https://packaging.python.org/en/latest/specifications/platform-compatibility-tags/
[3]: https://cibuildwheel.pypa.io/en/stable/options/#options-summary

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Link: https://lore.kernel.org/r/20240611205041.1448276-1-vfazio@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
9 months agotools: tests: avoid splitting and globbing
Kent Gibson [Mon, 3 Jun 2024 11:56:28 +0000 (19:56 +0800)]
tools: tests: avoid splitting and globbing

Fix shellcheck SC2046[1], SC2068[2], SC2068[3] and SC2206[4], all of
which are related to avoiding word splitting and globbing.

[1] https://www.shellcheck.net/wiki/SC2046
[2] https://www.shellcheck.net/wiki/SC2068
[3] https://www.shellcheck.net/wiki/SC2086
[4] https://www.shellcheck.net/wiki/SC2206

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240603115628.102616-9-warthog618@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
9 months agotools: tests: shellcheck don't follow sourced file
Kent Gibson [Mon, 3 Jun 2024 11:56:27 +0000 (19:56 +0800)]
tools: tests: shellcheck don't follow sourced file

Fix shellcheck SC1091 - not following.

Use a directive to prevent shellcheck complaining about sourcing
shunit2, which we don't care to check.

[1] https://www.shellcheck.net/wiki/SC1091

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240603115628.102616-8-warthog618@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
9 months agotools: tests: check exit code directly
Kent Gibson [Mon, 3 Jun 2024 11:56:26 +0000 (19:56 +0800)]
tools: tests: check exit code directly

Fix shellcheck SC2181[1] - check exit code directly.

[1] https://www.shellcheck.net/wiki/SC2181

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240603115628.102616-7-warthog618@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
9 months agotools: tests: don't use variables in printf format string
Kent Gibson [Mon, 3 Jun 2024 11:56:25 +0000 (19:56 +0800)]
tools: tests: don't use variables in printf format string

Fix shellcheck SC2059[1] - don't use variables in the printf format
string.

[1] https://www.shellcheck.net/wiki/SC2059

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240603115628.102616-6-warthog618@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
9 months agotools: tests: use read -r to avoid mangling backslashes
Kent Gibson [Mon, 3 Jun 2024 11:56:24 +0000 (19:56 +0800)]
tools: tests: use read -r to avoid mangling backslashes

Fix shellcheck SC2162[1] - read without -r will mangle backslashes.

[1] https://www.shellcheck.net/wiki/SC2162

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240603115628.102616-5-warthog618@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
9 months agotools: tests: fix unused variables
Kent Gibson [Mon, 3 Jun 2024 11:56:23 +0000 (19:56 +0800)]
tools: tests: fix unused variables

Fix shellckeck SC2034[1] - foo appears unused.

Prefix intentionally unused variables with "_" and remove variables
not actually used.

[1] https://www.shellcheck.net/wiki/SC2034

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240603115628.102616-4-warthog618@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
9 months agotools: tests: declare and assign separately
Kent Gibson [Mon, 3 Jun 2024 11:56:22 +0000 (19:56 +0800)]
tools: tests: declare and assign separately

Fix shellcheck SC2155[1] - declare and assign separately to avoid
masking return values.

[1] https://www.shellcheck.net/wiki/SC2155

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240603115628.102616-3-warthog618@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
9 months agotools: tests: don't mix string and array
Kent Gibson [Mon, 3 Jun 2024 11:56:21 +0000 (19:56 +0800)]
tools: tests: don't mix string and array

Fix shellcheck SC2145[1] - argument mixes string and array.

Separate the command from the array of arguments to avoid mixing.

[1] https://www.shellcheck.net/wiki/SC2145

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240603115628.102616-2-warthog618@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
9 months agobindings: cxx: Migrate C++ tests to use Catch2 v3
Khem Raj [Fri, 31 May 2024 18:42:23 +0000 (11:42 -0700)]
bindings: cxx: Migrate C++ tests to use Catch2 v3

Catch2 v3.x has API changes which needs to be addressed
in the tests themselves, hence this changeset is to fix
those.

Signed-off-by: Khem Raj <raj.khem@gmail.com>
Link: https://lore.kernel.org/r/20240531184223.3949069-1-raj.khem@gmail.com
[Bartosz: added a version requirement (>= 3.0) for catch2 to configure.ac]
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
10 months agotools: tests: remove dependency on grep
Bartosz Golaszewski [Tue, 28 May 2024 08:25:51 +0000 (10:25 +0200)]
tools: tests: remove dependency on grep

We only use grep in one place where we don't really need it as we can use
find directly.

Reported-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Suggested-by: Kent Gibson <warthog618@gmail.com>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20240528-fix-bash-tests-v3-4-e9b5be2ba8bf@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
10 months agotools: tests: remove unneeded ';' in while loops
Bartosz Golaszewski [Tue, 28 May 2024 08:25:50 +0000 (10:25 +0200)]
tools: tests: remove unneeded ';' in while loops

We're already breaking the line between while and do so there's no need
for the ';' character.

Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20240528-fix-bash-tests-v3-3-e9b5be2ba8bf@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
10 months agotools: tests: use "$@" instead of $*
Bartosz Golaszewski [Tue, 28 May 2024 08:25:49 +0000 (10:25 +0200)]
tools: tests: use "$@" instead of $*

$@ does not break up quoted arguments which is what we want in all cases
in the bash test-suite. Use it instead of $*. While at it: prevent
globbing with double quotes but allow variable expansion.

Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20240528-fix-bash-tests-v3-2-e9b5be2ba8bf@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
10 months agotools: tests: use tabs for indentation consistently
Bartosz Golaszewski [Tue, 28 May 2024 08:25:48 +0000 (10:25 +0200)]
tools: tests: use tabs for indentation consistently

Replace all spaces used for indentation with tabs.

Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20240528-fix-bash-tests-v3-1-e9b5be2ba8bf@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
10 months agobindings: python: fix python-tests-run make target
Kent Gibson [Sun, 26 May 2024 11:32:34 +0000 (19:32 +0800)]
bindings: python: fix python-tests-run make target

The python-tests-run target is broken as it does not correctly split
lines.  It also calls Python directly rather then through the $PYTHON
variable.

Fix the line splitting and call Python using the $PYTHON variable.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240526113234.253859-3-warthog618@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
10 months agobindings: python: add Testing section to README
Kent Gibson [Sun, 26 May 2024 11:32:33 +0000 (19:32 +0800)]
bindings: python: add Testing section to README

Add a section describing how to run the test suite.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240526113234.253859-2-warthog618@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>