Skip to content

Commit

Permalink
add platform version to SDK comparison
Browse files Browse the repository at this point in the history
Signed-off-by: Igor Davidyuk <[email protected]>
  • Loading branch information
igor-davidyuk committed Aug 1, 2024
1 parent 1e4821d commit c353860
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 43 deletions.
3 changes: 1 addition & 2 deletions geti_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,8 @@
"""

from ._version import __version__ # noqa: F401
from .geti import Geti
from .prediction_visualization.visualizer import Visualizer

__version__ = "2.2.0"

__all__ = ["Geti", "Visualizer"]
15 changes: 15 additions & 0 deletions geti_sdk/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (C) 2022 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions
# and limitations under the License.

__version__ = "2.3.0"
37 changes: 37 additions & 0 deletions geti_sdk/geti.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
from typing import Dict, List, Optional, Sequence, Tuple, Union

import numpy as np
from packaging.version import Version

from geti_sdk.data_models.enums.dataset_format import DatasetFormat
from geti_sdk.import_export.import_export_module import GetiIE
from geti_sdk.platform_versions import GETI_116_VERSION

from ._version import __version__ as sdk_version_string
from .annotation_readers import AnnotationReader, DatumAnnotationReader
from .data_models import (
Dataset,
Expand Down Expand Up @@ -57,6 +60,8 @@
DEFAULT_LOG_LEVEL = logging.INFO
DEFAULT_LOG_FORMAT = "%(asctime)s - %(levelname)s - %(message)s"

logging.captureWarnings(True)


class Geti:
"""
Expand Down Expand Up @@ -170,10 +175,15 @@ def __init__(
"please update the `server_config` accordingly."
)

# Set the Intel Geti SDK version
self.sdk_version = Version(sdk_version_string)
# Initialize session and get workspace id
self.session = GetiSession(
server_config=server_config,
)
# Now that the connection to the server is established, check the platform version
self._check_platform_version()
# Get workspace ID
if workspace_id is None:
workspace_id = get_default_workspace_id(self.session)
self.workspace_id = workspace_id
Expand All @@ -189,6 +199,33 @@ def __init__(
# Cache of deployment clients for projects in the workspace
self._deployment_clients: Dict[str, DeploymentClient] = {}

def _check_platform_version(self) -> None:
"""
Check the version of the Intel® Geti™ server that this `Geti` instance is
connected to. If the version is not supported by the SDK, a warning will be
issued.
:raises: ValueError if the Intel® Geti™ server version is not supported by the
Intel® Geti™ SDK.
"""
# Get the build version without a timestamp
platform_version = self.session.version.version
# Check if the platform version is newer than the SDK version
if platform_version > self.sdk_version:
warnings.warn(
f"The Intel® Geti™ server version {platform_version} is newer than "
f"the Geti SDK version {self.sdk_version}. Some features may not be "
"supported and you may encounter errors.\n"
"Please update the Intel Geti SDK to the latest version"
"with `pip install --upgrade geti-sdk`."
)
# Check if the platform version is older than the last supported version
if self.session.version < GETI_116_VERSION:
raise ValueError(
"The Intel® Geti™ server version is not supported by this Intel Geti SDK package. Please "
"update the Intel® Geti™ server to version 2.0 or later, or use a previous version of the SDK."
)

@property
def projects(self) -> List[Project]:
"""
Expand Down
7 changes: 1 addition & 6 deletions geti_sdk/http_session/geti_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from requests.structures import CaseInsensitiveDict
from urllib3.exceptions import InsecureRequestWarning

from geti_sdk.platform_versions import GETI_116_VERSION, GetiVersion
from geti_sdk.platform_versions import GetiVersion

from .exception import GetiRequestException
from .server_config import ServerCredentialConfig, ServerTokenConfig
Expand Down Expand Up @@ -110,11 +110,6 @@ def __init__(
# Get server version
self._product_info = self._get_product_info_and_set_api_version()
self._organization_id: Optional[str] = self._get_organization_id()
if self.version < GETI_116_VERSION:
raise ValueError(
"The Intel® Geti™ server version is not supported by this SDK. Please "
"update the Intel® Geti™ server to version 2.0 or later, or us the previous version of the SDK."
)

@property
@cache
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_requirements(filename: str) -> List[str]:
return required_packages


with open("geti_sdk/__init__.py", "r", encoding="utf-8") as init_file:
with open("geti_sdk/_version.py", "r", encoding="utf-8") as init_file:
for line in init_file:
line = line.strip()
if line.startswith("__version__"):
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/unit_tests/geti.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def _mocked_session_factory(
mocker.patch(
"geti_sdk.http_session.geti_session.GetiSession._get_product_info_and_set_api_version",
return_value={
"product-version": "2.0.0",
"build-version": "2.0.0-test-20240417130126",
"product-version": "2.3.0",
"build-version": "2.3.0-test-20240417130126",
"smtp-defined": "True",
"environment": "on-prem",
},
Expand Down
32 changes: 0 additions & 32 deletions tests/pre-merge/unit/http_session/test_geti_session_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,35 +92,3 @@ def test_authentication_onprem(
# Username and password will soon be deprecated for on-prem
with pytest.warns():
GetiSession(fxt_mocked_server_credential_config)

def test_authentication_legacy(
self,
fxt_mocked_server_credential_config,
mocker: MockerFixture,
):
# Arrange
mocker.patch(
"geti_sdk.http_session.geti_session.GetiSession.platform_serving_mode",
ONPREM_MODE,
)
mocker.patch(
"geti_sdk.http_session.geti_session.GetiSession._get_product_info_and_set_api_version",
return_value={
"product-version": "1.8.0",
"build-version": "1.8.0-test-20240417130126",
"smtp-defined": "True",
"environment": "on-prem",
},
)
mocker.patch(
"geti_sdk.http_session.geti_session.GetiSession._get_organization_id",
return_value="dummy_org_id",
)
mocker.patch(
"geti_sdk.http_session.geti_session.GetiSession.authenticate_with_password"
)

# Act
# Legacy platforms are no longer supported
with pytest.raises(ValueError):
GetiSession(fxt_mocked_server_credential_config)
54 changes: 54 additions & 0 deletions tests/pre-merge/unit/test_geti_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from geti_sdk import Geti
from geti_sdk.data_models import Project
from geti_sdk.http_session import ServerCredentialConfig, ServerTokenConfig
from geti_sdk.http_session.geti_session import ONPREM_MODE
from tests.helpers.constants import DUMMY_HOST, DUMMY_PASSWORD, DUMMY_TOKEN, DUMMY_USER


Expand Down Expand Up @@ -72,6 +73,59 @@ def test_exception_flow_init(
geti = Geti(host=DUMMY_HOST, token=DUMMY_TOKEN)
assert "x-api-key" in geti.session.headers.keys()

def test_connection_to_legacy_platform(
self,
fxt_mocked_server_credential_config,
fxt_mocked_session_factory,
mocker: MockerFixture,
):
# Arrange
mocker.patch(
"geti_sdk.http_session.geti_session.GetiSession.platform_serving_mode",
ONPREM_MODE,
)
mocker.patch(
"geti_sdk.http_session.geti_session.GetiSession._get_product_info_and_set_api_version",
return_value={
"product-version": "1.8.0",
"build-version": "1.8.0-test-20240417130126",
"smtp-defined": "True",
"environment": "on-prem",
},
)
mocker.patch(
"geti_sdk.http_session.geti_session.GetiSession._get_organization_id",
return_value="dummy_org_id",
)
mocker.patch(
"geti_sdk.http_session.geti_session.GetiSession.authenticate_with_password"
)

# Act
# Legacy platforms are no longer supported
with pytest.raises(ValueError):
Geti(host=DUMMY_HOST, server_config=fxt_mocked_server_credential_config)

def test_connection_to_legacynewer_platform(
self,
fxt_mocked_session_factory,
mocker: MockerFixture,
):
# Arrange
mocker.patch("geti_sdk.geti.GetiSession", new=fxt_mocked_session_factory)
mock_session = fxt_mocked_session_factory()
mocker.patch("geti_sdk.geti.get_default_workspace_id", return_value=1)
# Decrease the minor version for the SDK
platform_version = str(mock_session.version.version).split(".")
mocker.patch(
"geti_sdk.geti.sdk_version_string",
f"{platform_version[0]}.{int(platform_version[1]) - 1}.0",
)

# Act
with pytest.warns():
Geti(host=DUMMY_HOST, token=DUMMY_TOKEN)

def test_logout(self, mocker: MockerFixture, fxt_mocked_geti: Geti):
# Arrange
mock_logout = mocker.patch.object(fxt_mocked_geti.session, "logout")
Expand Down

0 comments on commit c353860

Please sign in to comment.