Skip to content

Commit 7c89e23

Browse files
authored
Merge pull request #711 from ianmcorvidae/optionalize-deps
Make several dependencies optional (dotmap, print_color, and pyqrcode)
2 parents 89b41c1 + 4673824 commit 7c89e23

File tree

5 files changed

+38
-18
lines changed

5 files changed

+38
-18
lines changed

meshtastic/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ def onConnection(interface, topic=pub.AUTO_TOPIC): # called when we (re)connect
8080

8181
import google.protobuf.json_format
8282
import serial # type: ignore[import-untyped]
83-
from dotmap import DotMap # type: ignore[import-untyped]
8483
from google.protobuf.json_format import MessageToJson
8584
from pubsub import pub # type: ignore[import-untyped]
8685
from tabulate import tabulate

meshtastic/__main__.py

+23-8
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,21 @@
1313
import time
1414
from typing import List, Optional
1515

16-
import pyqrcode # type: ignore[import-untyped]
16+
try:
17+
import pyqrcode # type: ignore[import-untyped]
18+
except ImportError as e:
19+
pyqrcode = None
20+
1721
import yaml
1822
from google.protobuf.json_format import MessageToDict
1923
from pubsub import pub # type: ignore[import-untyped]
2024

21-
import meshtastic.test
25+
try:
26+
import meshtastic.test
27+
have_test = True
28+
except ImportError as e:
29+
have_test = False
30+
2231
import meshtastic.util
2332
from meshtastic import BROADCAST_ADDR, mt_config, remote_hardware
2433
from meshtastic.ble_interface import BLEInterface
@@ -891,8 +900,11 @@ def setSimpleConfig(modem_preset):
891900
else:
892901
urldesc = "Primary channel URL"
893902
print(f"{urldesc}: {url}")
894-
qr = pyqrcode.create(url)
895-
print(qr.terminal())
903+
if pyqrcode is not None:
904+
qr = pyqrcode.create(url)
905+
print(qr.terminal())
906+
else:
907+
print("Install pyqrcode to view a QR code printed to terminal.")
896908

897909
log_set: Optional = None # type: ignore[annotation-unchecked]
898910
# we need to keep a reference to the logset so it doesn't get GCed early
@@ -1143,11 +1155,14 @@ def common():
11431155
parser.print_help(sys.stderr)
11441156
meshtastic.util.our_exit("", 1)
11451157
elif args.test:
1146-
result = meshtastic.test.testAll()
1147-
if not result:
1148-
meshtastic.util.our_exit("Warning: Test was not successful.")
1158+
if not have_test:
1159+
meshtastic.util.our_exit("Test module could not be important. Ensure you have the 'dotmap' module installed.")
11491160
else:
1150-
meshtastic.util.our_exit("Test was a success.", 0)
1161+
result = meshtastic.test.testAll()
1162+
if not result:
1163+
meshtastic.util.our_exit("Warning: Test was not successful.")
1164+
else:
1165+
meshtastic.util.our_exit("Test was a success.", 0)
11511166
else:
11521167
if args.seriallog == "stdout":
11531168
logfile = sys.stdout

meshtastic/mesh_interface.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
from typing import Any, Callable, Dict, List, Optional, Union
1616

1717
import google.protobuf.json_format
18-
import print_color # type: ignore[import-untyped]
18+
try:
19+
import print_color # type: ignore[import-untyped]
20+
except ImportError as e:
21+
print_color = None
22+
1923
from pubsub import pub # type: ignore[import-untyped]
2024
from tabulate import tabulate
2125

@@ -153,7 +157,7 @@ def __exit__(self, exc_type, exc_value, trace):
153157
@staticmethod
154158
def _printLogLine(line, interface):
155159
"""Print a line of log output."""
156-
if interface.debugOut == sys.stdout:
160+
if print_color is not None and interface.debugOut == sys.stdout:
157161
# this isn't quite correct (could cause false positives), but currently our formatting differs between different log representations
158162
if "DEBUG" in line:
159163
print_color.print(line, color="cyan", end=None)

poetry.lock

+5-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ readme = "README.md"
1010
python = "^3.9,<3.14" # 3.9 is needed for pandas, bleak requires <3.14
1111
pyserial = "^3.5"
1212
protobuf = ">=4.21.12"
13-
dotmap = "^1.3.30"
14-
pyqrcode = "^1.2.1"
1513
tabulate = "^0.9.0"
1614
requests = "^2.31.0"
1715
pyyaml = "^6.0.1"
1816
pypubsub = "^4.0.3"
1917
bleak = "^0.22.3"
2018
packaging = "^24.0"
21-
print-color = "^0.4.6"
19+
pyqrcode = { version = "^1.2.1", optional = true }
20+
dotmap = { version = "^1.3.30", optional = true }
21+
print-color = { version = "^0.4.6", optional = true }
2222
dash = { version = "^2.17.1", optional = true }
2323
pytap2 = { version = "^2.3.0", optional = true }
2424
dash-bootstrap-components = { version = "^1.6.0", optional = true }
@@ -64,6 +64,7 @@ ipywidgets = "^8.1.3"
6464
jupyterlab-widgets = "^3.0.11"
6565

6666
[tool.poetry.extras]
67+
cli = ["pyqrcode", "print-color", "dotmap"]
6768
tunnel = ["pytap2"]
6869
analysis = ["dash", "dash-bootstrap-components", "pandas", "pandas-stubs"]
6970

0 commit comments

Comments
 (0)