Skip to content

Commit

Permalink
Added a step in client initialization that validates the client is up…
Browse files Browse the repository at this point in the history
… to date enough for the server (#68)
  • Loading branch information
KevinCLydon authored Jul 11, 2024
1 parent f8474fa commit 63bbec1
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ All notable changes to Cellarium CAS client will be documented in this file.
The format is based on `Keep a Changelog <https://keepachangelog.com/en/1.0.0/>`_,
and this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0.html>`_.

1.4.7 - 2024-07-09
------------------

Added
~~~~~
- Add check in client initialization to ensure the current version of the client code is compatbile with the selected CAS server

1.4.6 - 2024-06-12
------------------

Expand Down
18 changes: 17 additions & 1 deletion cellarium/cas/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import anndata
from deprecated import deprecated

from cellarium.cas import _io, constants, data_preparation, exceptions, service, settings
from cellarium.cas import _io, constants, data_preparation, exceptions, service, settings, version
from cellarium.cas.service import action_context_manager

CHUNK_SIZE_ANNOTATE_DEFAULT = 1000
Expand Down Expand Up @@ -66,6 +66,8 @@ def __init__(
if "should_ask_for_feedback" in self.user_info:
self.should_show_feedback = self.user_info["should_ask_for_feedback"]

self.validate_version()

# Retrieving General Info
application_info = self.cas_api_service.get_application_info()

Expand Down Expand Up @@ -108,6 +110,20 @@ def feedback_opt_out(self):
self.user_info = self.cas_api_service.feedback_opt_out()
self._print("Successfully opted out. You will no longer receive requests to provide feedback.")

def validate_version(self):
"""
Validate that this version of the client library is compatible with the selected server.
"""
client_version = version.get_version()
version_validation_info = self.cas_api_service.validate_version(version_str=client_version)
if version_validation_info["is_valid"]:
self._print(f"Client version {client_version} is compatible with selected server.")
else:
raise exceptions.ClientTooOldError(
f"Client version {client_version} is older than the minimum version for this server {version_validation_info['min_version']}. "
f"Please update the client to the latest version using 'pip install cellarium-cas --upgrade'."
)

def validate_and_sanitize_input_data(
self,
adata: anndata.AnnData,
Expand Down
1 change: 1 addition & 0 deletions cellarium/cas/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
GET_SCHEMA_BY_NAME = f"{_API_GENERAL_ENDPOINT_PREFIX}/feature-schema/{{schema_name}}"
LIST_MODELS = f"{_API_GENERAL_ENDPOINT_PREFIX}/list-models"
GET_USER_QUOTA = f"{_API_GENERAL_ENDPOINT_PREFIX}/quota"
VALIDATE_VERSION = f"{_API_GENERAL_ENDPOINT_PREFIX}/validate-client-version"
# Cell Analysis
ANNOTATE_CELL_TYPE_SUMMARY_STATS_STRATEGY = (
f"{_API_CELL_OPERATIONS_ENDPOINT_PREFIX}/annotate-cell-type-summary-statistics-strategy"
Expand Down
4 changes: 4 additions & 0 deletions cellarium/cas/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ class DataValidationError(CASBaseError):

class QuotaExceededError(CASBaseError):
pass


class ClientTooOldError(CASBaseError):
pass
9 changes: 9 additions & 0 deletions cellarium/cas/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,15 @@ def get_feedback_answer_link(self) -> str:
)
)

def validate_version(self, version_str: str) -> t.Dict[str, t.Any]:
"""
Validate client version with the server to see if it is compatible.
Would raise 400 Bad Request if version is not compatible.
:return: Void
"""
return self.post_json(endpoint=endpoints.VALIDATE_VERSION, data={"client_version": version_str})

def get_feature_schemas(self) -> t.List[str]:
"""
Retrieve a list of feature schemas that exist in Cellarium Cloud CAS
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/test_cas_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ def _mock_constructor_calls(self):
{"schema_name": TEST_SCHEMA},
],
)
self._mock_response(
url=f"{TEST_URL}/api/cellarium-general/validate-client-version",
status_code=200,
response_body={"is_valid": True, "min_version": "1.4.0"},
method="post",
)

def _mock_annotate_matrix_cell_type_summary_statistics_strategy_calls(
self, num_cells: int = 3, num_features: int = 3
Expand Down

0 comments on commit 63bbec1

Please sign in to comment.