|
23 | 23 | import os.path as osp
|
24 | 24 | import sys
|
25 | 25 | import time
|
| 26 | +import warnings |
26 | 27 | from io import BytesIO
|
27 | 28 | from xmlrpc.client import Binary, ServerProxy
|
28 | 29 |
|
|
32 | 33 | from guidata.env import execenv
|
33 | 34 | from guidata.userconfig import get_config_basedir
|
34 | 35 |
|
| 36 | +import cdlclient |
35 | 37 | from cdlclient import simplemodel
|
36 | 38 | from cdlclient.baseproxy import SimpleBaseProxy
|
37 | 39 | from cdlclient.simplemodel import ImageObj, SignalObj
|
@@ -194,6 +196,33 @@ def json_to_items(json_str: str | None) -> list:
|
194 | 196 | return items
|
195 | 197 |
|
196 | 198 |
|
| 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 | + |
197 | 226 | class SimpleRemoteProxy(SimpleBaseProxy):
|
198 | 227 | """Object representing a proxy/client to DataLab XML-RPC server.
|
199 | 228 | 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:
|
247 | 276 | self.port = port
|
248 | 277 | self._cdl = ServerProxy(f"http://127.0.0.1:{port}", allow_none=True)
|
249 | 278 | try:
|
250 |
| - self.get_version() |
| 279 | + version = self.get_version() |
251 | 280 | except ConnectionRefusedError as exc:
|
252 | 281 | 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 | + ) |
253 | 291 |
|
254 | 292 | def connect(
|
255 | 293 | self,
|
|
0 commit comments