@@ -7,19 +7,67 @@ Python bindings for libgpiod.
This module wraps the native C API of libgpiod in a set of python classes.
"""
-from . import _ext
-from . import line
-from .chip import Chip
-from .chip_info import ChipInfo
-from .edge_event import EdgeEvent
-from .exception import ChipClosedError, RequestReleasedError
-from .info_event import InfoEvent
-from .line_request import LineRequest
-from .line_settings import LineSettings
+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 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
+__all__ += (
+ chip.__all__
+ + chip_info.__all__
+ + edge_event.__all__
+ + exception.__all__
+ + info_event.__all__
+ + line.__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:
"""
@@ -1,6 +1,11 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
# SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl>
+from collections import Counter
+from datetime import timedelta
+from errno import ENOENT
+from typing import Optional, Union
+
from . import _ext
from .chip_info import ChipInfo
from .exception import ChipClosedError
@@ -8,16 +13,10 @@ from .info_event import InfoEvent
from .internal import poll_fd
from .line import Value
from .line_info import LineInfo
-from .line_settings import LineSettings, _line_settings_to_ext
from .line_request import LineRequest
-from collections import Counter
-from collections.abc import Iterable
-from datetime import timedelta
-from errno import ENOENT
-from select import select
-from typing import Union, Optional
+from .line_settings import LineSettings, _line_settings_to_ext
-__all__ = "Chip"
+__all__ = ["Chip"]
class Chip:
@@ -4,7 +4,7 @@
from dataclasses import dataclass
-__all__ = "ChipInfo"
+__all__ = ["ChipInfo"]
@dataclass(frozen=True, repr=False)
@@ -1,11 +1,12 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
# SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl>
-from . import _ext
from dataclasses import dataclass
from enum import Enum
-__all__ = "EdgeEvent"
+from . import _ext
+
+__all__ = ["EdgeEvent"]
@dataclass(frozen=True, init=False, repr=False)
@@ -1,12 +1,13 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
# SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl>
-from . import _ext
-from .line_info import LineInfo
from dataclasses import dataclass
from enum import Enum
-__all__ = "InfoEvent"
+from . import _ext
+from .line_info import LineInfo
+
+__all__ = ["InfoEvent"]
@dataclass(frozen=True, init=False, repr=False)
@@ -5,7 +5,7 @@ from datetime import timedelta
from select import select
from typing import Optional, Union
-__all__ = []
+__all__ = ["poll_fd"]
def poll_fd(fd: int, timeout: Optional[Union[timedelta, float]] = None) -> bool:
@@ -2,9 +2,10 @@
# SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl>
-from . import _ext
from enum import Enum
+from . import _ext
+
__all__ = ["Value", "Direction", "Bias", "Drive", "Edge", "Clock"]
@@ -1,12 +1,12 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
# SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl>
-from . import _ext
from dataclasses import dataclass
from datetime import timedelta
-from gpiod.line import Direction, Bias, Drive, Edge, Clock
-__all__ = "LineInfo"
+from .line import Bias, Clock, Direction, Drive, Edge
+
+__all__ = ["LineInfo"]
@dataclass(frozen=True, init=False, repr=False)
@@ -1,17 +1,18 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
# SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl>
+from collections.abc import Iterable
+from datetime import timedelta
+from typing import Optional, Union
+
from . import _ext
from .edge_event import EdgeEvent
from .exception import RequestReleasedError
from .internal import poll_fd
from .line import Value
from .line_settings import LineSettings, _line_settings_to_ext
-from collections.abc import Iterable
-from datetime import timedelta
-from typing import Optional, Union
-__all__ = "LineRequest"
+__all__ = ["LineRequest"]
class LineRequest:
@@ -1,12 +1,13 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
# SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl>
-from . import _ext
from dataclasses import dataclass
from datetime import timedelta
-from gpiod.line import Direction, Bias, Drive, Edge, Clock, Value
-__all__ = "LineSettings"
+from . import _ext
+from .line import Bias, Clock, Direction, Drive, Edge, Value
+
+__all__ = ["LineSettings"]
@dataclass(repr=False)
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. Also, fix instances where `line` wasn't imported via a relative import. The library now consistently uses relative imports for submodules. Signed-off-by: Vincent Fazio <vfazio@xes-inc.com> --- bindings/python/gpiod/__init__.py | 66 +++++++++++++++++++++++++++++----- bindings/python/gpiod/chip.py | 15 ++++---- bindings/python/gpiod/chip_info.py | 2 +- bindings/python/gpiod/edge_event.py | 5 +-- bindings/python/gpiod/info_event.py | 7 ++-- bindings/python/gpiod/internal.py | 2 +- bindings/python/gpiod/line.py | 3 +- bindings/python/gpiod/line_info.py | 6 ++-- bindings/python/gpiod/line_request.py | 9 ++--- bindings/python/gpiod/line_settings.py | 7 ++-- 10 files changed, 87 insertions(+), 35 deletions(-)