Skip to content

Commit 72de803

Browse files
committed
Attempt to make powermon stuff optional, hopefully allowing pypi release
1 parent 84ffdcd commit 72de803

3 files changed

Lines changed: 40 additions & 26 deletions

File tree

meshtastic/__main__.py

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,19 @@
2323
from meshtastic import BROADCAST_ADDR, mt_config, remote_hardware
2424
from meshtastic.ble_interface import BLEInterface
2525
from meshtastic.mesh_interface import MeshInterface
26-
from meshtastic.powermon import (
27-
PowerMeter,
28-
PowerStress,
29-
PPK2PowerSupply,
30-
RidenPowerSupply,
31-
SimPowerSupply,
32-
)
26+
try:
27+
from meshtastic.powermon import (
28+
PowerMeter,
29+
PowerStress,
30+
PPK2PowerSupply,
31+
RidenPowerSupply,
32+
SimPowerSupply,
33+
)
34+
have_powermon = True
35+
powermon_exception = None
36+
except ImportError as e:
37+
have_powermon = False
38+
powermon_exception = e
3339
from meshtastic.protobuf import channel_pb2, config_pb2, portnums_pb2
3440
from meshtastic.slog import LogSet
3541
from meshtastic.version import get_active_version
@@ -895,16 +901,22 @@ def setSimpleConfig(modem_preset):
895901
# we need to keep a reference to the logset so it doesn't get GCed early
896902

897903
if args.slog or args.power_stress:
898-
# Setup loggers
899-
global meter # pylint: disable=global-variable-not-assigned
900-
log_set = LogSet(
901-
interface, args.slog if args.slog != "default" else None, meter
902-
)
904+
if have_powermon:
905+
# Setup loggers
906+
global meter # pylint: disable=global-variable-not-assigned
907+
log_set = LogSet(
908+
interface, args.slog if args.slog != "default" else None, meter
909+
)
910+
911+
if args.power_stress:
912+
stress = PowerStress(interface)
913+
stress.run()
914+
closeNow = True # exit immediately after stress test
915+
else:
916+
meshtastic.util.our_exit("The powermon module could not be loaded. "
917+
"You may need to run `poetry install --with powermon`. "
918+
"Import Error was: " + powermon_exception)
903919

904-
if args.power_stress:
905-
stress = PowerStress(interface)
906-
stress.run()
907-
closeNow = True # exit immediately after stress test
908920

909921
if args.listen:
910922
closeNow = False
@@ -1101,7 +1113,8 @@ def common():
11011113
meshtastic.util.support_info()
11021114
meshtastic.util.our_exit("", 0)
11031115

1104-
create_power_meter()
1116+
if have_powermon:
1117+
create_power_meter()
11051118

11061119
if args.ch_index is not None:
11071120
channelIndex = int(args.ch_index)

poetry.lock

Lines changed: 3 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ pyyaml = "^6.0.1"
2121
pypubsub = "^4.0.3"
2222
bleak = "^0.21.1"
2323
packaging = "^24.0"
24-
riden = { git = "https://github.com/geeksville/riden.git#1.2.1" }
2524
parse = "^1.20.2"
26-
ppk2-api = "^0.9.2"
2725
pyarrow = "^16.1.0"
2826
platformdirs = "^4.2.2"
2927
print-color = "^0.4.6"
@@ -50,6 +48,13 @@ types-pyyaml = "^6.0.12.20240311"
5048
pyarrow-stubs = "^10.0.1.7"
5149
pandas-stubs = "^2.2.2.240603"
5250

51+
[tool.poetry.group.powermon]
52+
optional = true
53+
54+
[tool.poetry.group.powermon.dependencies]
55+
riden = { git = "https://github.com/geeksville/riden.git#1.2.1" }
56+
ppk2-api = "^0.9.2"
57+
5358
# If you are doing power analysis you might want these extra devtools
5459
[tool.poetry.group.analysis]
5560
optional = true

0 commit comments

Comments
 (0)