mirror of
https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git
synced 2026-10-24 00:48:53 +03:00
* Update pyproject.toml to require Python 3.10+ for runtime * Update mypy's target version to 3.10 syntax * Drop ruff's target version as it's inferred by the project's requires-python value * Remove the linter settings that ignored UP007 & UP0045 * Update type annotations to conform to active linter rules Closes: https://github.com/brgl/libgpiod/issues/151 Signed-off-by: Vincent Fazio <vfazio@gmail.com> Link: https://patch.msgid.link/20260329182832.39824-1-vfazio@gmail.com Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
124 lines
2.9 KiB
Python
124 lines
2.9 KiB
Python
# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
# SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl>
|
|
|
|
"""
|
|
Python bindings for libgpiod.
|
|
|
|
This module wraps the native C API of libgpiod in a set of python classes.
|
|
"""
|
|
|
|
from collections.abc import Iterable
|
|
|
|
from . import (
|
|
_ext,
|
|
chip,
|
|
chip_info,
|
|
edge_event,
|
|
exception,
|
|
info_event,
|
|
line,
|
|
line_info,
|
|
line_request,
|
|
line_settings,
|
|
version,
|
|
)
|
|
from .chip import *
|
|
from .chip_info import *
|
|
from .edge_event import *
|
|
from .exception import *
|
|
from .info_event import *
|
|
from .line_info import *
|
|
from .line_request import *
|
|
from .line_settings import *
|
|
from .version import __version__
|
|
|
|
api_version = _ext.api_version
|
|
|
|
# public submodules
|
|
__all__ = [
|
|
"chip",
|
|
"chip_info",
|
|
"edge_event",
|
|
"exception",
|
|
"info_event",
|
|
"line",
|
|
"line_info",
|
|
"line_request",
|
|
"line_settings",
|
|
"version",
|
|
]
|
|
|
|
# re-export public submodule exports
|
|
# do not re-export line objects, this is not an oversight
|
|
__all__ += (
|
|
chip.__all__
|
|
+ chip_info.__all__
|
|
+ edge_event.__all__
|
|
+ exception.__all__
|
|
+ info_event.__all__
|
|
+ line_info.__all__
|
|
+ line_request.__all__
|
|
+ line_settings.__all__
|
|
)
|
|
|
|
# module methods/attributes
|
|
__all__ += [
|
|
"__version__",
|
|
"api_version",
|
|
"is_gpiochip_device",
|
|
"request_lines",
|
|
]
|
|
|
|
|
|
def is_gpiochip_device(path: str) -> bool:
|
|
"""
|
|
Check if the file pointed to by path is a GPIO chip character device.
|
|
|
|
Args:
|
|
path
|
|
Path to the file that should be checked.
|
|
|
|
Returns:
|
|
Returns true if so, False otherwise.
|
|
"""
|
|
return _ext.is_gpiochip_device(path)
|
|
|
|
|
|
def request_lines(
|
|
path: str,
|
|
config: dict[Iterable[int | str] | int | str, LineSettings | None],
|
|
consumer: str | None = None,
|
|
event_buffer_size: int | None = None,
|
|
output_values: dict[int | str, line.Value] | None = None,
|
|
) -> LineRequest:
|
|
"""
|
|
Open a GPIO chip pointed to by 'path', request lines according to the
|
|
configuration arguments, close the chip and return the request object.
|
|
|
|
Args:
|
|
path
|
|
Path to the GPIO character device file.
|
|
config:
|
|
Dictionary mapping offsets or names (or tuples thereof) to
|
|
LineSettings. If None is passed as the value of the mapping,
|
|
default settings are used.
|
|
consumer:
|
|
Consumer string to use for this request.
|
|
event_buffer_size:
|
|
Size of the kernel edge event buffer to configure for this request.
|
|
output_values:
|
|
Dictionary mapping offsets or names to line.Value. This can be used
|
|
to set the desired output values globally while reusing LineSettings
|
|
for more lines.
|
|
|
|
Returns:
|
|
Returns a new LineRequest object.
|
|
"""
|
|
with Chip(path) as chip:
|
|
return chip.request_lines(
|
|
config=config,
|
|
consumer=consumer,
|
|
event_buffer_size=event_buffer_size,
|
|
output_values=output_values,
|
|
)
|