Skip to content

Commit

Permalink
Re-add packaging based version check for IoT Hub ARM SDK. (#432)
Browse files Browse the repository at this point in the history
* Re-add packaging based version check for IoT Hub ARM SDK.
* Remove un-used import.
  • Loading branch information
digimaun authored Sep 15, 2021
1 parent 33335d9 commit 370b02b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
10 changes: 8 additions & 2 deletions azext_iot/common/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from datetime import datetime
from knack.log import get_logger
from knack.util import CLIError
from azext_iot.constants import IOTHUB_MGMT_SDK_PACKAGE_NAME

logger = get_logger(__name__)

Expand Down Expand Up @@ -447,7 +446,14 @@ def is_iso8601_time(self, to_validate: str) -> bool:


def ensure_iothub_sdk_min_version(min_ver):
return test_import_and_version(IOTHUB_MGMT_SDK_PACKAGE_NAME, min_ver)
from packaging import version

try:
from azure.mgmt.iothub import __version__ as iot_sdk_version
except ImportError:
from azure.mgmt.iothub._version import VERSION as iot_sdk_version

return version.parse(iot_sdk_version) >= version.parse(min_ver)


def scantree(path):
Expand Down
9 changes: 3 additions & 6 deletions azext_iot/tests/utility/test_iot_utility_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,10 @@ class TestVersionComparison(object):
],
)
def test_ensure_iothub_sdk_min_version(self, mocker, current, minimum, expected):
def get_version(package):
return current

try:
mocker.patch("importlib.metadata.version", get_version)
except ModuleNotFoundError:
mocker.patch("importlib_metadata.version", get_version)
mocker.patch("azure.mgmt.iothub.__version__", current)
except:
mocker.patch("azure.mgmt.iothub._version.VERSION", current)

assert ensure_iothub_sdk_min_version(minimum) == expected

Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@
DEPENDENCIES = [
"jsonschema~=3.2.0",
"importlib_metadata;python_version<'3.8'",
"azure-iot-device~=2.5",
"tqdm~=4.62"
"azure-iot-device~=2.5",
"tqdm~=4.62",
"packaging"
]
EXTRAS = {"uamqp": ["uamqp~=1.2"]}

Expand Down

0 comments on commit 370b02b

Please sign in to comment.