mirror of
https://github.com/meshtastic/python.git
synced 2026-01-04 22:08:00 -05:00
use importlib.metadata and packaging.version instead of pkg_resources
This commit is contained in:
@@ -9,7 +9,6 @@ import platform
|
||||
import sys
|
||||
import time
|
||||
|
||||
import pkg_resources
|
||||
import pyqrcode
|
||||
import yaml
|
||||
from google.protobuf.json_format import MessageToDict
|
||||
@@ -18,6 +17,7 @@ from pubsub import pub
|
||||
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
|
||||
@@ -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(
|
||||
|
||||
@@ -12,12 +12,13 @@ import time
|
||||
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])
|
||||
@@ -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(
|
||||
@@ -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
meshtastic/version.py
Normal file
11
meshtastic/version.py
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user