Skip to content

Commit

Permalink
Fixed mmh3 installation
Browse files Browse the repository at this point in the history
  • Loading branch information
samson0v committed Mar 6, 2023
1 parent 41f3a8a commit 7b1ffcc
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
14 changes: 13 additions & 1 deletion sdk_utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
from random import randint
from zlib import crc32
from hashlib import sha256, sha384, sha512, md5
from mmh3 import hash, hash128
import logging
from subprocess import CalledProcessError

from utils import install_package

try:
install_package('mmh3')
except CalledProcessError:
install_package('pymmh3')

try:
from mmh3 import hash, hash128
except ImportError:
from pymmh3 import hash, hash128

log = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@
long_description_content_type="text/markdown",
python_requires=">=3.7",
packages=["."],
install_requires=['paho-mqtt>=1.6', 'requests', 'mmh3', 'simplejson'],
install_requires=['paho-mqtt>=1.6', 'requests', 'simplejson'],
download_url='https://github.com/thingsboard/thingsboard-python-client-sdk/archive/%s.tar.gz' % VERSION)
26 changes: 26 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from sys import executable
from subprocess import check_call, CalledProcessError


def install_package(package, version="upgrade"):
result = False
if version.lower() == "upgrade":
try:
result = check_call([executable, "-m", "pip", "install", package, "--upgrade", "--user"])
except CalledProcessError:
result = check_call([executable, "-m", "pip", "install", package, "--upgrade"])
else:
from pkg_resources import get_distribution
current_package_version = None
try:
current_package_version = get_distribution(package)
except Exception:
pass
if current_package_version is None or current_package_version != version:
installation_sign = "==" if ">=" not in version else ""
try:
result = check_call(
[executable, "-m", "pip", "install", package + installation_sign + version, "--user"])
except CalledProcessError:
result = check_call([executable, "-m", "pip", "install", package + installation_sign + version])
return result

0 comments on commit 7b1ffcc

Please sign in to comment.