Skip to content

Commit 6528b49

Browse files
committed
Remote client is now checking server version
1 parent fac4b76 commit 6528b49

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22

33
## Version 0.7.0 ##
44

5+
DataLab Simple Client is fully compatible with **DataLab 0.10.0** and above.
6+
With older versions of the DataLab server, some features may not work.
7+
58
💥 Changes:
69

710
* Added `toggle_auto_refresh` method to `SimpleRemoteProxy`
811
* Added `toggle_show_titles` method to `SimpleRemoteProxy`
12+
* Remote client is now checking the server version and shows a warning message if
13+
the server version may not be fully compatible with the client version.
914

1015
## Version 0.6.0 ##
1116

cdlclient/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
from cdlclient.remote import SimpleRemoteProxy # noqa: F401
1919

2020
__version__ = "0.7.0"
21+
__required_server_version__ = "0.10.0"
2122
__docurl__ = "https://cdlclient.readthedocs.io/en/latest/"
2223
__homeurl__ = "https://github.com/Codra-Ingenierie-Informatique/DataLabSimpleClient/"

cdlclient/remote.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import os.path as osp
2424
import sys
2525
import time
26+
import warnings
2627
from io import BytesIO
2728
from xmlrpc.client import Binary, ServerProxy
2829

@@ -32,6 +33,7 @@
3233
from guidata.env import execenv
3334
from guidata.userconfig import get_config_basedir
3435

36+
import cdlclient
3537
from cdlclient import simplemodel
3638
from cdlclient.baseproxy import SimpleBaseProxy
3739
from cdlclient.simplemodel import ImageObj, SignalObj
@@ -194,6 +196,33 @@ def json_to_items(json_str: str | None) -> list:
194196
return items
195197

196198

199+
def is_version_at_least(version1: str, version2: str) -> bool:
200+
"""
201+
Compare two version strings to check if the first version is at least
202+
equal to the second.
203+
204+
Args:
205+
version1 (str): The first version string.
206+
version2 (str): The second version string.
207+
208+
Returns:
209+
bool: True if version1 is greater than or equal to version2, False otherwise.
210+
"""
211+
# Split the version strings into parts
212+
parts1 = [int(part) for part in version1.split(".")]
213+
parts2 = [int(part) for part in version2.split(".")]
214+
215+
# Compare each part
216+
for part1, part2 in zip(parts1, parts2):
217+
if part1 > part2:
218+
return True
219+
elif part1 < part2:
220+
return False
221+
222+
# Check if version1 is shorter and thus less than version2
223+
return len(parts1) >= len(parts2)
224+
225+
197226
class SimpleRemoteProxy(SimpleBaseProxy):
198227
"""Object representing a proxy/client to DataLab XML-RPC server.
199228
This object is used to call DataLab functions from a Python script.
@@ -247,9 +276,18 @@ def __connect_to_server(self, port: str | None = None) -> None:
247276
self.port = port
248277
self._cdl = ServerProxy(f"http://127.0.0.1:{port}", allow_none=True)
249278
try:
250-
self.get_version()
279+
version = self.get_version()
251280
except ConnectionRefusedError as exc:
252281
raise ConnectionRefusedError("DataLab is currently not running") from exc
282+
# If DataLab version is not compatible with this client, show a warning using
283+
# standard `warnings` module:
284+
if not is_version_at_least(version, cdlclient.__required_server_version__):
285+
warnings.warn(
286+
f"DataLab version {version} is not fully compatible with "
287+
f"DataLab Simple Client version {cdlclient.__version__}.\n"
288+
f"Please upgrade DataLab to {cdlclient.__required_server_version__} "
289+
f"or higher."
290+
)
253291

254292
def connect(
255293
self,

0 commit comments

Comments
 (0)