Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions meshtastic/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import sys
import time

import pkg_resources
import pyqrcode
import yaml
from google.protobuf.json_format import MessageToDict
Expand All @@ -18,6 +17,7 @@
import meshtastic.test
import meshtastic.util
from meshtastic import channel_pb2, config_pb2, portnums_pb2, remote_hardware
from meshtastic.version import get_active_version
from meshtastic.__init__ import BROADCAST_ADDR
from meshtastic.ble_interface import BLEInterface
from meshtastic.globals import Globals
Expand Down Expand Up @@ -1399,7 +1399,7 @@ def initParser():

parser.set_defaults(deprecated=None)

the_version = pkg_resources.get_distribution("meshtastic").version
the_version = get_active_version()
parser.add_argument("--version", action="version", version=f"{the_version}")

parser.add_argument(
Expand Down
19 changes: 13 additions & 6 deletions meshtastic/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
import traceback
from queue import Queue

import pkg_resources
import packaging.version as pkg_version
import requests
import serial
import serial.tools.list_ports

from meshtastic.supported_device import supported_devices
from meshtastic.version import get_active_version

"""Some devices such as a seger jlink we never want to accidentally open"""
blacklistVids = dict.fromkeys([0x1366])
Expand Down Expand Up @@ -269,7 +270,7 @@ def support_info():
print(f" Machine: {platform.uname().machine}")
print(f" Encoding (stdin): {sys.stdin.encoding}")
print(f" Encoding (stdout): {sys.stdout.encoding}")
the_version = pkg_resources.get_distribution("meshtastic").version
the_version = get_active_version()
pypi_version = check_if_newer_version()
if pypi_version:
print(
Expand Down Expand Up @@ -599,9 +600,15 @@ def check_if_newer_version():
pypi_version = data["info"]["version"]
except Exception:
pass
act_version = pkg_resources.get_distribution("meshtastic").version
if pypi_version and pkg_resources.parse_version(
pypi_version
) <= pkg_resources.parse_version(act_version):
act_version = get_active_version()

try:
parsed_act_version = pkg_version.parse(act_version)
parsed_pypi_version = pkg_version.parse(pypi_version)
except pkg_version.InvalidVersion:
return pypi_version

if parsed_pypi_version <= parsed_act_version:
return None

return pypi_version
11 changes: 11 additions & 0 deletions meshtastic/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import sys
try:
from importlib.metadata import version
except:
import pkg_resources

def get_active_version():
if "importlib.metadata" in sys.modules:
return version("meshtastic")
else:
return pkg_resources.get_distribution("meshtastic").version
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ pytap2
pdoc3
pypubsub
bleak
packaging
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"timeago>=1.0.15",
"pyyaml",
"bleak>=0.21.1",
"packaging",
],
extras_require={"tunnel": ["pytap2>=2.0.0"]},
python_requires=">=3.7",
Expand Down