Skip to content

Commit f6af834

Browse files
committed
SimpleRemoteProxy constructor: add autoconnect=True
1 parent af4c9d6 commit f6af834

File tree

8 files changed

+30
-11
lines changed

8 files changed

+30
-11
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# DataLab Simple Client Releases #
22

3+
## Version 0.9.0 ##
4+
5+
DataLab Simple Client is fully compatible with **DataLab 0.11.0** and above.
6+
With older versions of the DataLab server, some features may not work.
7+
8+
💥 Changes:
9+
10+
* Remote API (`SimpleRemoteProxy`):
11+
* Changed constructor signature to accept `autoconnect` as argument,
12+
defaulting to `True`
13+
* Thus, when creating a `SimpleRemoteProxy` instance, the connection to the
14+
server is now established automatically by default (i.e. same behavior as
15+
DataLab's `cdl.proxy.RemoteProxy` class)
16+
317
## Version 0.8.1 ##
418

519
DataLab Simple Client is fully compatible with **DataLab 0.11.0** and above.

cdlclient/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from cdlclient.baseproxy import SimpleBaseProxy # noqa: F401
1818
from cdlclient.remote import SimpleRemoteProxy # noqa: F401
1919

20-
__version__ = "0.8.1"
20+
__version__ = "0.9.0"
2121
__required_server_version__ = "0.11.0"
2222
__docurl__ = "https://cdlclient.readthedocs.io/en/latest/"
2323
__homeurl__ = "https://github.com/Codra-Ingenierie-Informatique/DataLabSimpleClient/"

cdlclient/remote.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,19 @@ class SimpleRemoteProxy(SimpleBaseProxy):
230230
This is a subset of DataLab's `RemoteClient` class, with only the methods
231231
that do not require DataLab object model to be implemented.
232232
233+
Args:
234+
autoconnect: If True, automatically connect to DataLab XML-RPC server.
235+
Defaults to True.
236+
237+
Raises:
238+
ConnectionRefusedError: DataLab is currently not running
239+
233240
Examples:
234241
Here is a simple example of how to use SimpleRemoteProxy in a Python script
235242
or in a Jupyter notebook:
236243
237244
>>> from cdlclient import SimpleRemoteProxy
238-
>>> proxy = SimpleRemoteProxy()
239-
>>> proxy.connect()
245+
>>> proxy = SimpleRemoteProxy() # autoconnect is on by default
240246
Connecting to DataLab XML-RPC server...OK (port: 28867)
241247
>>> proxy.get_version()
242248
'1.0.0'
@@ -254,10 +260,12 @@ class SimpleRemoteProxy(SimpleBaseProxy):
254260
array([1., 2., 3.])
255261
"""
256262

257-
def __init__(self) -> None:
263+
def __init__(self, autoconnect: bool = True) -> None:
258264
super().__init__()
259265
self.port: str = None
260266
self._cdl: ServerProxy
267+
if autoconnect:
268+
self.connect()
261269

262270
def __connect_to_server(self, port: str | None = None) -> None:
263271
"""Connect to DataLab XML-RPC server.

cdlclient/tests/connect_dialog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
def test_dialog():
2020
"""Test connection dialog"""
21-
proxy = SimpleRemoteProxy()
21+
proxy = SimpleRemoteProxy(autoconnect=False)
2222
with qt_app_context():
2323
dlg = ConnectionDialog(proxy.connect)
2424
if dlg.exec():

cdlclient/tests/get_object_dialog.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
def test_dialog():
1919
"""Test connection dialog"""
2020
proxy = SimpleRemoteProxy()
21-
proxy.connect()
2221
with qt_app_context():
2322
# 1. Select an image or signal object
2423
dlg = GetObjectDialog(None, proxy)

cdlclient/tests/remoteclient_app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class HostWindow(AbstractClientWindow):
7373
def init_cdl(self):
7474
"""Open DataLab test"""
7575
if self.cdl is None:
76-
self.cdl: SimpleRemoteProxy = SimpleRemoteProxy()
76+
self.cdl = SimpleRemoteProxy(autoconnect=False)
7777
connect_dlg = ConnectionDialog(self.cdl.connect, self)
7878
ok = connect_dlg.exec()
7979
if ok:

cdlclient/tests/remoteclient_unit.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ def multiple_commands(remote: SimpleRemoteProxy):
7777
def test():
7878
"""Remote client test"""
7979
remote = SimpleRemoteProxy()
80-
remote.connect()
8180
execenv.print("Executing multiple commands...", end="")
8281
multiple_commands(remote)
8382
execenv.print("OK")

doc/remote_example.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@
1414
import numpy as np
1515

1616
# DataLab remote control client:
17-
from cdlclient import SimpleRemoteProxy
17+
from cdlclient import SimpleRemoteProxy as RemoteProxy
1818

1919
# %% Connecting to DataLab current session
2020

21-
proxy = SimpleRemoteProxy()
22-
proxy.connect()
21+
proxy = RemoteProxy()
2322

2423
# %% Executing commands in DataLab (...)
2524

0 commit comments

Comments
 (0)