Skip to content

Commit

Permalink
Merge pull request #711 from ianmcorvidae/optionalize-deps
Browse files Browse the repository at this point in the history
Make several dependencies optional (dotmap, print_color, and pyqrcode)
  • Loading branch information
ianmcorvidae authored Dec 13, 2024
2 parents 89b41c1 + 4673824 commit 7c89e23
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 18 deletions.
1 change: 0 additions & 1 deletion meshtastic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def onConnection(interface, topic=pub.AUTO_TOPIC): # called when we (re)connect

import google.protobuf.json_format
import serial # type: ignore[import-untyped]
from dotmap import DotMap # type: ignore[import-untyped]
from google.protobuf.json_format import MessageToJson
from pubsub import pub # type: ignore[import-untyped]
from tabulate import tabulate
Expand Down
31 changes: 23 additions & 8 deletions meshtastic/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,21 @@
import time
from typing import List, Optional

import pyqrcode # type: ignore[import-untyped]
try:
import pyqrcode # type: ignore[import-untyped]
except ImportError as e:
pyqrcode = None

import yaml
from google.protobuf.json_format import MessageToDict
from pubsub import pub # type: ignore[import-untyped]

import meshtastic.test
try:
import meshtastic.test
have_test = True
except ImportError as e:
have_test = False

import meshtastic.util
from meshtastic import BROADCAST_ADDR, mt_config, remote_hardware
from meshtastic.ble_interface import BLEInterface
Expand Down Expand Up @@ -891,8 +900,11 @@ def setSimpleConfig(modem_preset):
else:
urldesc = "Primary channel URL"
print(f"{urldesc}: {url}")
qr = pyqrcode.create(url)
print(qr.terminal())
if pyqrcode is not None:
qr = pyqrcode.create(url)
print(qr.terminal())
else:
print("Install pyqrcode to view a QR code printed to terminal.")

log_set: Optional = None # type: ignore[annotation-unchecked]
# we need to keep a reference to the logset so it doesn't get GCed early
Expand Down Expand Up @@ -1143,11 +1155,14 @@ def common():
parser.print_help(sys.stderr)
meshtastic.util.our_exit("", 1)
elif args.test:
result = meshtastic.test.testAll()
if not result:
meshtastic.util.our_exit("Warning: Test was not successful.")
if not have_test:
meshtastic.util.our_exit("Test module could not be important. Ensure you have the 'dotmap' module installed.")
else:
meshtastic.util.our_exit("Test was a success.", 0)
result = meshtastic.test.testAll()
if not result:
meshtastic.util.our_exit("Warning: Test was not successful.")
else:
meshtastic.util.our_exit("Test was a success.", 0)
else:
if args.seriallog == "stdout":
logfile = sys.stdout
Expand Down
8 changes: 6 additions & 2 deletions meshtastic/mesh_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
from typing import Any, Callable, Dict, List, Optional, Union

import google.protobuf.json_format
import print_color # type: ignore[import-untyped]
try:
import print_color # type: ignore[import-untyped]
except ImportError as e:
print_color = None

from pubsub import pub # type: ignore[import-untyped]
from tabulate import tabulate

Expand Down Expand Up @@ -153,7 +157,7 @@ def __exit__(self, exc_type, exc_value, trace):
@staticmethod
def _printLogLine(line, interface):
"""Print a line of log output."""
if interface.debugOut == sys.stdout:
if print_color is not None and interface.debugOut == sys.stdout:
# this isn't quite correct (could cause false positives), but currently our formatting differs between different log representations
if "DEBUG" in line:
print_color.print(line, color="cyan", end=None)
Expand Down
9 changes: 5 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ readme = "README.md"
python = "^3.9,<3.14" # 3.9 is needed for pandas, bleak requires <3.14
pyserial = "^3.5"
protobuf = ">=4.21.12"
dotmap = "^1.3.30"
pyqrcode = "^1.2.1"
tabulate = "^0.9.0"
requests = "^2.31.0"
pyyaml = "^6.0.1"
pypubsub = "^4.0.3"
bleak = "^0.22.3"
packaging = "^24.0"
print-color = "^0.4.6"
pyqrcode = { version = "^1.2.1", optional = true }
dotmap = { version = "^1.3.30", optional = true }
print-color = { version = "^0.4.6", optional = true }
dash = { version = "^2.17.1", optional = true }
pytap2 = { version = "^2.3.0", optional = true }
dash-bootstrap-components = { version = "^1.6.0", optional = true }
Expand Down Expand Up @@ -64,6 +64,7 @@ ipywidgets = "^8.1.3"
jupyterlab-widgets = "^3.0.11"

[tool.poetry.extras]
cli = ["pyqrcode", "print-color", "dotmap"]
tunnel = ["pytap2"]
analysis = ["dash", "dash-bootstrap-components", "pandas", "pandas-stubs"]

Expand Down

0 comments on commit 7c89e23

Please sign in to comment.