gpiod 2.2.4__tar.gz → 2.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. {gpiod-2.2.4 → gpiod-2.4.0}/MANIFEST.in +1 -1
  2. {gpiod-2.2.4/gpiod.egg-info → gpiod-2.4.0}/PKG-INFO +35 -15
  3. {gpiod-2.2.4 → gpiod-2.4.0}/README.md +17 -0
  4. {gpiod-2.2.4 → gpiod-2.4.0}/build_tests.py +11 -7
  5. gpiod-2.4.0/gpiod/__init__.py +124 -0
  6. gpiod-2.4.0/gpiod/_ext.pyi +94 -0
  7. gpiod-2.4.0/gpiod/_internal.py +37 -0
  8. {gpiod-2.2.4 → gpiod-2.4.0}/gpiod/chip.py +86 -75
  9. {gpiod-2.2.4 → gpiod-2.4.0}/gpiod/chip_info.py +8 -5
  10. {gpiod-2.2.4 → gpiod-2.4.0}/gpiod/edge_event.py +14 -4
  11. {gpiod-2.2.4 → gpiod-2.4.0}/gpiod/exception.py +2 -2
  12. {gpiod-2.2.4 → gpiod-2.4.0}/gpiod/ext/chip.c +31 -0
  13. {gpiod-2.2.4 → gpiod-2.4.0}/gpiod/info_event.py +14 -7
  14. {gpiod-2.2.4 → gpiod-2.4.0}/gpiod/line.py +23 -2
  15. {gpiod-2.2.4 → gpiod-2.4.0}/gpiod/line_info.py +17 -5
  16. {gpiod-2.2.4 → gpiod-2.4.0}/gpiod/line_request.py +85 -56
  17. {gpiod-2.2.4 → gpiod-2.4.0}/gpiod/line_settings.py +16 -7
  18. gpiod-2.4.0/gpiod/py.typed +0 -0
  19. {gpiod-2.2.4 → gpiod-2.4.0}/gpiod/version.py +1 -1
  20. {gpiod-2.2.4 → gpiod-2.4.0/gpiod.egg-info}/PKG-INFO +35 -15
  21. {gpiod-2.2.4 → gpiod-2.4.0}/gpiod.egg-info/SOURCES.txt +5 -3
  22. {gpiod-2.2.4 → gpiod-2.4.0}/include/gpiod.h +0 -36
  23. {gpiod-2.2.4 → gpiod-2.4.0}/lib/line-config.c +18 -1
  24. gpiod-2.4.0/libgpiod-version.txt +1 -0
  25. gpiod-2.4.0/pyproject.toml +88 -0
  26. {gpiod-2.2.4 → gpiod-2.4.0}/setup.py +1 -17
  27. gpiod-2.4.0/tests/__init__.py +12 -0
  28. {gpiod-2.2.4 → gpiod-2.4.0}/tests/__main__.py +3 -4
  29. {gpiod-2.2.4 → gpiod-2.4.0}/tests/gpiosim/__init__.py +3 -1
  30. {gpiod-2.2.4 → gpiod-2.4.0}/tests/gpiosim/chip.py +2 -1
  31. gpiod-2.4.0/tests/helpers.py +27 -0
  32. gpiod-2.4.0/tests/system/__init__.py +6 -0
  33. gpiod-2.4.0/tests/system/ext.c +79 -0
  34. {gpiod-2.2.4 → gpiod-2.4.0}/tests/tests_chip.py +50 -49
  35. {gpiod-2.2.4 → gpiod-2.4.0}/tests/tests_chip_info.py +16 -15
  36. {gpiod-2.2.4 → gpiod-2.4.0}/tests/tests_edge_event.py +69 -28
  37. {gpiod-2.2.4 → gpiod-2.4.0}/tests/tests_info_event.py +59 -40
  38. {gpiod-2.2.4 → gpiod-2.4.0}/tests/tests_line.py +4 -3
  39. {gpiod-2.2.4 → gpiod-2.4.0}/tests/tests_line_info.py +20 -20
  40. {gpiod-2.2.4 → gpiod-2.4.0}/tests/tests_line_request.py +255 -102
  41. {gpiod-2.2.4 → gpiod-2.4.0}/tests/tests_line_settings.py +10 -11
  42. {gpiod-2.2.4 → gpiod-2.4.0}/tests/tests_module.py +19 -20
  43. gpiod-2.2.4/gpiod/__init__.py +0 -54
  44. gpiod-2.2.4/gpiod/internal.py +0 -18
  45. gpiod-2.2.4/libgpiod-version.txt +0 -1
  46. gpiod-2.2.4/pyproject.toml +0 -5
  47. gpiod-2.2.4/tests/__init__.py +0 -17
  48. gpiod-2.2.4/tests/helpers.py +0 -16
  49. gpiod-2.2.4/tests/procname/__init__.py +0 -4
  50. gpiod-2.2.4/tests/procname/ext.c +0 -42
  51. {gpiod-2.2.4 → gpiod-2.4.0}/gpiod/ext/common.c +0 -0
  52. {gpiod-2.2.4 → gpiod-2.4.0}/gpiod/ext/internal.h +0 -0
  53. {gpiod-2.2.4 → gpiod-2.4.0}/gpiod/ext/line-config.c +0 -0
  54. {gpiod-2.2.4 → gpiod-2.4.0}/gpiod/ext/line-settings.c +0 -0
  55. {gpiod-2.2.4 → gpiod-2.4.0}/gpiod/ext/module.c +0 -0
  56. {gpiod-2.2.4 → gpiod-2.4.0}/gpiod/ext/request.c +0 -0
  57. {gpiod-2.2.4 → gpiod-2.4.0}/gpiod.egg-info/dependency_links.txt +0 -0
  58. {gpiod-2.2.4 → gpiod-2.4.0}/gpiod.egg-info/top_level.txt +0 -0
  59. {gpiod-2.2.4 → gpiod-2.4.0}/lib/chip-info.c +0 -0
  60. {gpiod-2.2.4 → gpiod-2.4.0}/lib/chip.c +0 -0
  61. {gpiod-2.2.4 → gpiod-2.4.0}/lib/edge-event.c +0 -0
  62. {gpiod-2.2.4 → gpiod-2.4.0}/lib/info-event.c +0 -0
  63. {gpiod-2.2.4 → gpiod-2.4.0}/lib/internal.c +0 -0
  64. {gpiod-2.2.4 → gpiod-2.4.0}/lib/internal.h +0 -0
  65. {gpiod-2.2.4 → gpiod-2.4.0}/lib/line-info.c +0 -0
  66. {gpiod-2.2.4 → gpiod-2.4.0}/lib/line-request.c +0 -0
  67. {gpiod-2.2.4 → gpiod-2.4.0}/lib/line-settings.c +0 -0
  68. {gpiod-2.2.4 → gpiod-2.4.0}/lib/misc.c +0 -0
  69. {gpiod-2.2.4 → gpiod-2.4.0}/lib/request-config.c +0 -0
  70. {gpiod-2.2.4 → gpiod-2.4.0}/lib/uapi/gpio.h +0 -0
  71. {gpiod-2.2.4 → gpiod-2.4.0}/setup.cfg +0 -0
  72. {gpiod-2.2.4 → gpiod-2.4.0}/tests/gpiosim/ext.c +0 -0
@@ -13,7 +13,7 @@ recursive-include gpiod/ext *.c
13
13
  recursive-include gpiod/ext *.h
14
14
 
15
15
  recursive-include tests/gpiosim *.c
16
- recursive-include tests/procname *.c
16
+ recursive-include tests/system *.c
17
17
 
18
18
  recursive-include lib *.c
19
19
  recursive-include lib *.h
@@ -1,23 +1,26 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: gpiod
3
- Version: 2.2.4
3
+ Version: 2.4.0
4
4
  Summary: Python bindings for libgpiod
5
- Home-page: https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git
6
- Author: Bartosz Golaszewski
7
- Author-email: brgl@bgdev.pl
8
- License: LGPLv2.1
5
+ Author-email: Bartosz Golaszewski <brgl@bgdev.pl>
6
+ License-Expression: LGPL-2.1-or-later
7
+ Project-URL: Homepage, https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git
8
+ Project-URL: Issues, https://github.com/brgl/libgpiod/issues/
9
9
  Platform: linux
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Operating System :: POSIX :: Linux
12
+ Classifier: Typing :: Typed
13
+ Classifier: Programming Language :: Python
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
10
22
  Requires-Python: >=3.9.0
11
23
  Description-Content-Type: text/markdown
12
- Dynamic: author
13
- Dynamic: author-email
14
- Dynamic: description
15
- Dynamic: description-content-type
16
- Dynamic: home-page
17
- Dynamic: license
18
- Dynamic: platform
19
- Dynamic: requires-python
20
- Dynamic: summary
21
24
 
22
25
  <!-- SPDX-License-Identifier: CC-BY-SA-4.0 -->
23
26
  <!-- SPDX-FileCopyrightText: 2023 Phil Howard <phil@gadgetoid.com> -->
@@ -133,3 +136,20 @@ make python-tests-run
133
136
 
134
137
  from the `libgpiod/bindings/python` directory as root (necessary to be able
135
138
  to create the **gpio-sims** used for testing).
139
+
140
+ ## Linting/Formatting
141
+
142
+ When making changes, ensure type checks and linting still pass:
143
+
144
+ ```
145
+ python3 -m venv venv
146
+ . venv/bin/activate
147
+ pip install mypy ruff
148
+ mypy; ruff format; ruff check
149
+ ```
150
+
151
+ Ideally the gpiod library will continue to pass strict checks:
152
+
153
+ ```
154
+ mypy --strict
155
+ ```
@@ -112,3 +112,20 @@ make python-tests-run
112
112
 
113
113
  from the `libgpiod/bindings/python` directory as root (necessary to be able
114
114
  to create the **gpio-sims** used for testing).
115
+
116
+ ## Linting/Formatting
117
+
118
+ When making changes, ensure type checks and linting still pass:
119
+
120
+ ```
121
+ python3 -m venv venv
122
+ . venv/bin/activate
123
+ pip install mypy ruff
124
+ mypy; ruff format; ruff check
125
+ ```
126
+
127
+ Ideally the gpiod library will continue to pass strict checks:
128
+
129
+ ```
130
+ mypy --strict
131
+ ```
@@ -11,7 +11,7 @@ polluted with artefacts in build/
11
11
  Builds:
12
12
 
13
13
  tests/gpiosim/_ext.<target>.so
14
- tests/procname/_ext.<target>.so
14
+ tests/system/_ext.<target>.so
15
15
 
16
16
  """
17
17
 
@@ -61,9 +61,9 @@ gpiosim_ext = Extension(
61
61
  ],
62
62
  )
63
63
 
64
- procname_ext = Extension(
65
- "tests.procname._ext",
66
- sources=["tests/procname/ext.c"],
64
+ system_ext = Extension(
65
+ "tests.system._ext",
66
+ sources=["tests/system/ext.c"],
67
67
  define_macros=[("_GNU_SOURCE", "1")],
68
68
  extra_compile_args=["-Wall", "-Wextra"],
69
69
  )
@@ -71,7 +71,7 @@ procname_ext = Extension(
71
71
  dist = Distribution(
72
72
  {
73
73
  "name": "gpiod",
74
- "ext_modules": [gpiosim_ext, procname_ext, gpiod_ext],
74
+ "ext_modules": [gpiosim_ext, system_ext, gpiod_ext],
75
75
  "version": __version__,
76
76
  "platforms": ["linux"],
77
77
  }
@@ -82,9 +82,13 @@ try:
82
82
 
83
83
  configure()
84
84
  except ImportError:
85
- from distutils.log import DEBUG, set_verbosity
85
+ try:
86
+ from distutils.log import DEBUG, set_verbosity
86
87
 
87
- set_verbosity(DEBUG)
88
+ set_verbosity(DEBUG)
89
+ except ImportError:
90
+ # We can still build the tests, it will just be very quiet.
91
+ pass
88
92
 
89
93
  with tempfile.TemporaryDirectory(prefix="libgpiod-") as temp_dir:
90
94
  command = build_ext(dist)
@@ -0,0 +1,124 @@
1
+ # SPDX-License-Identifier: LGPL-2.1-or-later
2
+ # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl>
3
+
4
+ """
5
+ Python bindings for libgpiod.
6
+
7
+ This module wraps the native C API of libgpiod in a set of python classes.
8
+ """
9
+
10
+ from collections.abc import Iterable
11
+ from typing import Optional, Union
12
+
13
+ from . import (
14
+ _ext,
15
+ chip,
16
+ chip_info,
17
+ edge_event,
18
+ exception,
19
+ info_event,
20
+ line,
21
+ line_info,
22
+ line_request,
23
+ line_settings,
24
+ version,
25
+ )
26
+ from .chip import *
27
+ from .chip_info import *
28
+ from .edge_event import *
29
+ from .exception import *
30
+ from .info_event import *
31
+ from .line_info import *
32
+ from .line_request import *
33
+ from .line_settings import *
34
+ from .version import __version__
35
+
36
+ api_version = _ext.api_version
37
+
38
+ # public submodules
39
+ __all__ = [
40
+ "chip",
41
+ "chip_info",
42
+ "edge_event",
43
+ "exception",
44
+ "info_event",
45
+ "line",
46
+ "line_info",
47
+ "line_request",
48
+ "line_settings",
49
+ "version",
50
+ ]
51
+
52
+ # re-export public submodule exports
53
+ # do not re-export line objects, this is not an oversight
54
+ __all__ += (
55
+ chip.__all__
56
+ + chip_info.__all__
57
+ + edge_event.__all__
58
+ + exception.__all__
59
+ + info_event.__all__
60
+ + line_info.__all__
61
+ + line_request.__all__
62
+ + line_settings.__all__
63
+ )
64
+
65
+ # module methods/attributes
66
+ __all__ += [
67
+ "__version__",
68
+ "api_version",
69
+ "is_gpiochip_device",
70
+ "request_lines",
71
+ ]
72
+
73
+
74
+ def is_gpiochip_device(path: str) -> bool:
75
+ """
76
+ Check if the file pointed to by path is a GPIO chip character device.
77
+
78
+ Args:
79
+ path
80
+ Path to the file that should be checked.
81
+
82
+ Returns:
83
+ Returns true if so, False otherwise.
84
+ """
85
+ return _ext.is_gpiochip_device(path)
86
+
87
+
88
+ def request_lines(
89
+ path: str,
90
+ config: dict[Union[Iterable[Union[int, str]], int, str], Optional[LineSettings]],
91
+ consumer: Optional[str] = None,
92
+ event_buffer_size: Optional[int] = None,
93
+ output_values: Optional[dict[Union[int, str], line.Value]] = None,
94
+ ) -> LineRequest:
95
+ """
96
+ Open a GPIO chip pointed to by 'path', request lines according to the
97
+ configuration arguments, close the chip and return the request object.
98
+
99
+ Args:
100
+ path
101
+ Path to the GPIO character device file.
102
+ config:
103
+ Dictionary mapping offsets or names (or tuples thereof) to
104
+ LineSettings. If None is passed as the value of the mapping,
105
+ default settings are used.
106
+ consumer:
107
+ Consumer string to use for this request.
108
+ event_buffer_size:
109
+ Size of the kernel edge event buffer to configure for this request.
110
+ output_values:
111
+ Dictionary mapping offsets or names to line.Value. This can be used
112
+ to set the desired output values globally while reusing LineSettings
113
+ for more lines.
114
+
115
+ Returns:
116
+ Returns a new LineRequest object.
117
+ """
118
+ with Chip(path) as chip:
119
+ return chip.request_lines(
120
+ config=config,
121
+ consumer=consumer,
122
+ event_buffer_size=event_buffer_size,
123
+ output_values=output_values,
124
+ )
@@ -0,0 +1,94 @@
1
+ # SPDX-License-Identifier: LGPL-2.1-or-later
2
+ # SPDX-FileCopyrightText: 2024 Vincent Fazio <vfazio@gmail.com>
3
+
4
+ from typing import Optional
5
+
6
+ from .chip_info import ChipInfo
7
+ from .edge_event import EdgeEvent
8
+ from .info_event import InfoEvent
9
+ from .line import Value
10
+ from .line_info import LineInfo
11
+
12
+ class LineSettings:
13
+ def __init__(
14
+ self,
15
+ direction: int,
16
+ edge_detection: int,
17
+ bias: int,
18
+ drive: int,
19
+ active_low: bool,
20
+ debounce_period: int,
21
+ event_clock: int,
22
+ output_value: int,
23
+ ) -> None: ...
24
+
25
+ class LineConfig:
26
+ def __init__(self) -> None: ...
27
+ def add_line_settings(self, offsets: list[int], settings: LineSettings) -> None: ...
28
+ def set_output_values(self, global_output_values: list[Value]) -> None: ...
29
+
30
+ class Request:
31
+ def release(self) -> None: ...
32
+ def get_values(self, offsets: list[int], values: list[Value]) -> None: ...
33
+ def set_values(self, values: dict[int, Value]) -> None: ...
34
+ def reconfigure_lines(self, line_cfg: LineConfig) -> None: ...
35
+ def read_edge_events(self, max_events: Optional[int]) -> list[EdgeEvent]: ...
36
+ @property
37
+ def chip_name(self) -> str: ...
38
+ @property
39
+ def num_lines(self) -> int: ...
40
+ @property
41
+ def offsets(self) -> list[int]: ...
42
+ @property
43
+ def fd(self) -> int: ...
44
+
45
+ class Chip:
46
+ def __init__(self, path: str) -> None: ...
47
+ def get_info(self) -> ChipInfo: ...
48
+ def line_offset_from_id(self, id: str) -> int: ...
49
+ def get_line_info(self, offset: int, watch: bool) -> LineInfo: ...
50
+ def get_line_name(self, offset: int) -> Optional[str]: ...
51
+ def request_lines(
52
+ self,
53
+ line_cfg: LineConfig,
54
+ consumer: Optional[str],
55
+ event_buffer_size: Optional[int],
56
+ ) -> Request: ...
57
+ def read_info_event(self) -> InfoEvent: ...
58
+ def close(self) -> None: ...
59
+ def unwatch_line_info(self, line: int) -> None: ...
60
+ @property
61
+ def path(self) -> str: ...
62
+ @property
63
+ def fd(self) -> int: ...
64
+
65
+ def is_gpiochip_device(path: str) -> bool: ...
66
+
67
+ api_version: str
68
+
69
+ # enum constants
70
+ BIAS_AS_IS: int
71
+ BIAS_DISABLED: int
72
+ BIAS_PULL_DOWN: int
73
+ BIAS_PULL_UP: int
74
+ BIAS_UNKNOWN: int
75
+ CLOCK_HTE: int
76
+ CLOCK_MONOTONIC: int
77
+ CLOCK_REALTIME: int
78
+ DIRECTION_AS_IS: int
79
+ DIRECTION_INPUT: int
80
+ DIRECTION_OUTPUT: int
81
+ DRIVE_OPEN_DRAIN: int
82
+ DRIVE_OPEN_SOURCE: int
83
+ DRIVE_PUSH_PULL: int
84
+ EDGE_BOTH: int
85
+ EDGE_EVENT_TYPE_FALLING: int
86
+ EDGE_EVENT_TYPE_RISING: int
87
+ EDGE_FALLING: int
88
+ EDGE_NONE: int
89
+ EDGE_RISING: int
90
+ INFO_EVENT_TYPE_LINE_CONFIG_CHANGED: int
91
+ INFO_EVENT_TYPE_LINE_RELEASED: int
92
+ INFO_EVENT_TYPE_LINE_REQUESTED: int
93
+ VALUE_ACTIVE: int
94
+ VALUE_INACTIVE: int
@@ -0,0 +1,37 @@
1
+ # SPDX-License-Identifier: LGPL-2.1-or-later
2
+ # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl>
3
+
4
+ from __future__ import annotations
5
+
6
+ from datetime import timedelta
7
+ from select import select
8
+ from typing import TYPE_CHECKING, Optional, Union
9
+
10
+ if TYPE_CHECKING:
11
+ from collections.abc import Generator, Iterable
12
+
13
+ from .line_settings import LineSettings
14
+
15
+ __all__ = ["poll_fd", "config_iter"]
16
+
17
+
18
+ def poll_fd(fd: int, timeout: Optional[Union[timedelta, float]] = None) -> bool:
19
+ sec: Union[float, None]
20
+ if isinstance(timeout, timedelta):
21
+ sec = timeout.total_seconds()
22
+ else:
23
+ sec = timeout
24
+
25
+ readable, _, _ = select([fd], [], [], sec)
26
+ return True if fd in readable else False
27
+
28
+
29
+ def config_iter(
30
+ config: dict[Union[Iterable[Union[int, str]], int, str], Optional[LineSettings]],
31
+ ) -> Generator[tuple[Union[int, str], Optional[LineSettings]]]:
32
+ for key, settings in config.items():
33
+ if isinstance(key, int) or isinstance(key, str):
34
+ yield key, settings
35
+ else:
36
+ for subkey in key:
37
+ yield subkey, settings