diff --git a/lib/python/src/bailo/__init__.py b/lib/python/src/bailo/__init__.py index f8723bd56..17a83ce41 100644 --- a/lib/python/src/bailo/__init__.py +++ b/lib/python/src/bailo/__init__.py @@ -7,8 +7,9 @@ from __future__ import annotations import logging -# Package Version 2.3.3 -__version__ = "2.3.3" + +# Package Version 2.3.4 +__version__ = "2.3.4" from bailo.core.agent import Agent, PkiAgent, TokenAgent diff --git a/lib/python/src/bailo/helper/release.py b/lib/python/src/bailo/helper/release.py index 443656083..4add8a395 100644 --- a/lib/python/src/bailo/helper/release.py +++ b/lib/python/src/bailo/helper/release.py @@ -55,8 +55,6 @@ def __init__( if images is None: images = [] - if isinstance(version, str): - version = Version(version) self.version = version self.model_card_version = model_card_version @@ -285,7 +283,7 @@ def update(self) -> Any: """ return self.client.put_release( self.model_id, - str(self.version), + str(self.__version_raw), self.notes, self.draft, self.files, @@ -302,16 +300,39 @@ def delete(self) -> Any: return True + @property + def version(self): + return self.__version_obj + + @version.setter + def version(self, value): + if ("_Release__version_obj" not in self.__dict__) and ("_Release__version_raw" not in self.__dict__): + if isinstance(value, str): + if value.startswith("v"): + value = value[1:] + version_obj = Version.coerce(value) + elif isinstance(value, Version): + version_obj = value + else: + raise TypeError("Provided version not of a supported type.") + + self.__version_obj = version_obj + self.__version_raw = value + else: + raise BailoException( + "Version attribute has already been set once. You must create a new Release object to create a new version, or use Model.create_release()." + ) + def __repr__(self) -> str: return f"{self.__class__.__name__}({str(self)})" def __str__(self) -> str: - return f"{self.model_id} v{self.version}" + return f"{self.model_id} v{self.__version_obj}" def __eq__(self, other) -> bool: if not isinstance(other, self.__class__): return NotImplemented - return self.version == other.version + return self.__version_obj == other.__version_obj def __ne__(self, other): if not isinstance(other, self.__class__): @@ -321,22 +342,22 @@ def __ne__(self, other): def __lt__(self, other): if not isinstance(other, self.__class__): return NotImplemented - return self.version < other.version + return self.__version_obj < other.__version_obj def __le__(self, other): if not isinstance(other, self.__class__): return NotImplemented - return self.version <= other.version + return self.__version_obj <= other.__version_obj def __gt__(self, other): if not isinstance(other, self.__class__): return NotImplemented - return self.version > other.version + return self.__version_obj > other.__version_obj def __ge__(self, other): if not isinstance(other, self.__class__): return NotImplemented - return self.version >= other.version + return self.__version_obj >= other.__version_obj def __hash__(self) -> int: - return hash((self.model_id, self.version)) + return hash((self.model_id, self.__version_obj)) diff --git a/lib/python/tests/test_release.py b/lib/python/tests/test_release.py index 2a7f9ce72..4ea327b95 100644 --- a/lib/python/tests/test_release.py +++ b/lib/python/tests/test_release.py @@ -64,7 +64,7 @@ def test_create_get_from_version_update_and_delete_release( @pytest.mark.integration -def test_nonexistant_file_ids(integration_client, example_model): +def test_nonexistent_file_ids(integration_client, example_model): with pytest.raises(ResponseException): release = Release.create( client=integration_client, @@ -79,7 +79,7 @@ def test_nonexistant_file_ids(integration_client, example_model): @pytest.mark.integration -def create_two_release_with_same_semver(integration_client, example_model): +def test_create_two_release_with_same_semver(integration_client, example_model): Release.create( client=integration_client, model_id=example_model.model_id, version="1.1.0", model_card_version=1, notes="test" ) @@ -91,3 +91,11 @@ def create_two_release_with_same_semver(integration_client, example_model): model_card_version=1, notes="test", ) + + +@pytest.mark.integration +def test_retrieve_release_with_v_in_version(integration_client, example_model): + example_model.create_release(version="v2.0.0", notes=" ") + release = Release.from_version(client=integration_client, model_id=example_model.model_id, version="v2.0.0") + + assert str(release.version) == "2.0.0"