Skip to content

Commit 40c0ab3

Browse files
committed
Updated dependencies to have a fix for paho mqtt
1 parent 907ba1e commit 40c0ab3

File tree

3 files changed

+44
-16
lines changed

3 files changed

+44
-16
lines changed

setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
with open(path.join(this_directory, 'README.md')) as f:
2222
long_description = f.read()
2323

24-
VERSION = "1.12.0"
24+
VERSION = "1.13.0"
2525

2626
setup(
2727
version=VERSION,
@@ -35,5 +35,5 @@
3535
long_description_content_type="text/markdown",
3636
python_requires=">=3.9",
3737
packages=["."],
38-
install_requires=['paho-mqtt>=2.1.0', 'requests>=2.31.0', 'orjson'],
38+
install_requires=['tb-paho-mqtt-client>=2.1.1', 'requests>=2.31.0', 'orjson'],
3939
download_url='https://github.com/thingsboard/thingsboard-python-client-sdk/archive/%s.tar.gz' % VERSION)

tb_device_mqtt.py

+21
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,27 @@
1616
from copy import deepcopy
1717
from inspect import signature
1818
from time import sleep
19+
import importlib.util
20+
from utils import install_package
21+
22+
def check_tb_paho_mqtt_installed():
23+
try:
24+
spec = importlib.util.find_spec("paho.mqtt")
25+
if spec is None:
26+
return False
27+
module_path = spec.origin or "(built-in)"
28+
if 'tb-paho-mqtt-client' in module_path:
29+
return True
30+
else:
31+
return False
32+
except Exception as e:
33+
return False
34+
35+
if not check_tb_paho_mqtt_installed():
36+
try:
37+
install_package('tb-paho-mqtt-client', version='>=2.1.1')
38+
except Exception as e:
39+
raise ImportError("tb-paho-mqtt-client is not installed, please install it manually.") from e
1940

2041
import paho.mqtt.client as paho
2142
from math import ceil

utils.py

+21-14
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,34 @@
1414

1515
from sys import executable
1616
from subprocess import check_call, CalledProcessError
17+
from pkg_resources import get_distribution, DistributionNotFound
1718

1819

1920
def install_package(package, version="upgrade"):
2021
result = False
21-
if version.lower() == "upgrade":
22+
23+
def try_install(args):
2224
try:
23-
result = check_call([executable, "-m", "pip", "install", package, "--upgrade", "--user"])
25+
check_call([executable, "-m", "pip", *args])
26+
return True
2427
except CalledProcessError:
25-
result = check_call([executable, "-m", "pip", "install", package, "--upgrade"])
28+
return False
29+
30+
if version.lower() == "upgrade":
31+
args = ["install", package, "--upgrade"]
32+
result = try_install(args + ["--user"])
33+
if not result:
34+
result = try_install(args)
2635
else:
27-
from pkg_resources import get_distribution
28-
current_package_version = None
2936
try:
30-
current_package_version = get_distribution(package)
31-
except Exception:
37+
installed_version = get_distribution(package).version
38+
if installed_version == version:
39+
return True
40+
except DistributionNotFound:
3241
pass
33-
if current_package_version is None or current_package_version != version:
34-
installation_sign = "==" if ">=" not in version else ""
35-
try:
36-
result = check_call(
37-
[executable, "-m", "pip", "install", package + installation_sign + version, "--user"])
38-
except CalledProcessError:
39-
result = check_call([executable, "-m", "pip", "install", package + installation_sign + version])
42+
install_version = f"{package}=={version}" if ">=" not in version else f"{package}{version}"
43+
args = ["install", install_version]
44+
if not try_install(args + ["--user"]):
45+
result = try_install(args)
46+
4047
return result

0 commit comments

Comments
 (0)