Skip to content

Commit d2f2cf3

Browse files
committed
micropython/lora/lora/lora/__init__.py: ImportError would be raised incorrectly when the second hardware driver import failed,
because the error message would contain "lib.lora" instead of just "lora.". Signed-off-by: Breno RdV <[email protected]> Signed-off-by: Breno RdV <[email protected]>
1 parent 3251876 commit d2f2cf3

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

micropython/lora/lora/lora/__init__.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,34 @@
55

66
ok = False # Flag if at least one modem driver package is installed
77

8+
def _can_ignore_error(e):
9+
"""Check if ImportError can be ignored due to missing module."""
10+
return all(x in str(e) for x in ["no module named", "lora"])
11+
812
# Various lora "sub-packages"
913

1014
try:
1115
from .sx126x import * # noqa: F401
1216

1317
ok = True
1418
except ImportError as e:
15-
if "no module named 'lora." not in str(e):
19+
if not _can_ignore_error(e):
1620
raise
1721

1822
try:
1923
from .sx127x import * # noqa: F401
2024

2125
ok = True
2226
except ImportError as e:
23-
if "no module named 'lora." not in str(e) and not ok:
27+
if not _can_ignore_error(e):
2428
raise
2529

2630
try:
2731
from .stm32wl5 import * # noqa: F401
2832

2933
ok = True
3034
except ImportError as e:
31-
if "no module named 'lora." not in str(e) and not ok:
35+
if not _can_ignore_error(e):
3236
raise
3337

3438

@@ -38,3 +42,6 @@
3842
)
3943

4044
del ok
45+
46+
47+
__version__ = '0.2.1'

0 commit comments

Comments
 (0)