Browse Source

lazy load gpiod to protect our stable API against incompatilibities in hhk7734/python3-gpiod

Fabian Peter Hammerle 3 years ago
parent
commit
96e63ffc2b
1 changed files with 5 additions and 3 deletions
  1. 5 3
      cc1101/_gpio.py

+ 5 - 3
cc1101/_gpio.py

@@ -1,8 +1,6 @@
 import pathlib
 import typing
 
-import gpiod
-
 ChipSelector = typing.Union[pathlib.Path, str, int]
 
 
@@ -12,7 +10,11 @@ def _format_chip_selector(selector: ChipSelector) -> str:
     return str(selector)
 
 
-def get_line(chip_selector: ChipSelector, line_name: str) -> gpiod.line:
+def get_line(chip_selector: ChipSelector, line_name: str) -> "gpiod.line":  # type: ignore
+    # lazy import to protect stable API against incompatilibities in hhk7734/python3-gpiod
+    # e.g., incompatibility of v1.5.0 with python3.5&3.6 (python_requires not set)
+    import gpiod  # pylint: disable=import-outside-toplevel
+
     try:
         chip = gpiod.chip(chip_selector)
     except PermissionError as exc: