Skip to content
Closed
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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ To install using pip:
```bash
pip3 install tb-mqtt-client
```
### Note on dependencies

If you are running this on a platform that can't run packages with C library dependencies, and want to use the package `pymmh3` instead of `mmh3`, do the following instead:

```bash
pip3 install pymmh3 tb-mqtt-client --no-binary tb-mqtt-client
```
What happens by default, is that if python doesn't detect that `pymmh3` is installed, it will install `mmh3`. By running this command you install `pymmh3`. Therefore it is used, and `mmh3` is not installed.

`--no-binary tb-mqtt-client` is required.

## Getting Started

Expand Down
14 changes: 1 addition & 13 deletions sdk_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,8 @@
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
37 changes: 36 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#

from os import path
from pkg_resources import DistributionNotFound, get_distribution
from re import split
from setuptools import setup


Expand All @@ -23,6 +25,39 @@

VERSION = "1.5"

INSTALL_REQUIRES = ['tb-paho-mqtt-client>=1.6.3', 'requests>=2.31.0', 'simplejson']

# If none of packages in first installed, install second package
CHOOSE_INSTALL_REQUIRES = [
(
('pymmh3'),
'mmh3',
)
]

def choose_requirement(mains, secondary):
"""If some version of main requirement installed, return main,
else return secondary.

"""
chosen = secondary
for main in mains:
try:
name = split(r"[!<>=]", main)[0]
get_distribution(name)
chosen = main
break
except DistributionNotFound:
pass

return str(chosen)

def get_install_requirements(install_requires, choose_install_requires):
for mains, secondary in choose_install_requires:
install_requires.append(choose_requirement(mains, secondary))

return install_requires

setup(
version=VERSION,
name="tb-mqtt-client",
Expand All @@ -35,5 +70,5 @@
long_description_content_type="text/markdown",
python_requires=">=3.7",
packages=["."],
install_requires=['tb-paho-mqtt-client>=1.6.3', 'requests>=2.31.0', 'simplejson'],
install_requires=get_install_requirements(INSTALL_REQUIRES, CHOOSE_INSTALL_REQUIRES),
download_url='https://github.com/thingsboard/thingsboard-python-client-sdk/archive/%s.tar.gz' % VERSION)
40 changes: 0 additions & 40 deletions utils.py

This file was deleted.