Skip to content

Commit b7cfc79

Browse files
committed
Major overhaul
1 parent 42cf495 commit b7cfc79

23 files changed

Lines changed: 159 additions & 157 deletions

.coveragerc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ parallel = True
99
concurrency = multiprocessing,thread
1010

1111
omit =
12-
*/cdl_client/utils/tests.py
13-
*/cdl_client/tests/*
12+
*/cdlclient/utils/tests.py
13+
*/cdlclient/tests/*
1414
*/guidata/*
1515
*/plotpy/*
1616

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ coverage.xml
7373

7474
# Sphinx documentation
7575
docs/_build/
76-
cdl_client/data/doc/
76+
cdlclient/data/doc/
7777

7878
# PyBuilder
7979
target/

.isort.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[settings]
2-
known_first_party=cdl_client
2+
known_first_party=cdlclient

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"name": "Run Test Launcher",
99
"type": "python",
1010
"request": "launch",
11-
"program": "${workspaceFolder}/cdl_client/tests/__init__.py",
11+
"program": "${workspaceFolder}/cdlclient/tests/__init__.py",
1212
"console": "integratedTerminal",
1313
"envFile": "${workspaceFolder}/.env",
1414
"python": "${config:python.defaultInterpreterPath}",

CHANGELOG.md

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

33
## Version 0.1.0 ##
44

5-
First release of the DataLab Client.
5+
First release of the DataLab Simple Client.

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
## DataLab Client
1+
## DataLab Simple Client
22

3-
![DataLab](https://raw.githubusercontent.com/Codra-Ingenierie-Informatique/DataLab_Client/main/doc/images/DataLab-banner.png)
3+
![DataLab](https://raw.githubusercontent.com/Codra-Ingenierie-Informatique/DataLabSimpleClient/main/doc/images/DataLab-banner.png)
44

5-
[![license](https://img.shields.io/pypi/l/CDL_Client.svg)](./LICENSE)
6-
[![pypi version](https://img.shields.io/pypi/v/CDL_Client.svg)](https://pypi.org/project/CDL_Client/)
7-
[![PyPI status](https://img.shields.io/pypi/status/CDL_Client.svg)](https://github.com/Codra-Ingenierie-Informatique/DataLab_Client)
8-
[![PyPI pyversions](https://img.shields.io/pypi/pyversions/CDL_Client.svg)](https://pypi.python.org/pypi/CDL_Client/)
5+
[![license](https://img.shields.io/pypi/l/cdlclient.svg)](./LICENSE)
6+
[![pypi version](https://img.shields.io/pypi/v/cdlclient.svg)](https://pypi.org/project/cdlclient/)
7+
[![PyPI status](https://img.shields.io/pypi/status/cdlclient.svg)](https://github.com/Codra-Ingenierie-Informatique/DataLabSimpleClient)
8+
[![PyPI pyversions](https://img.shields.io/pypi/pyversions/cdlclient.svg)](https://pypi.python.org/pypi/cdlclient/)
99

1010
ℹ️ Created by [Codra](https://codra.net/)/[Pierre Raybaut](https://github.com/PierreRaybaut) in 2023, developed and maintained by DataLab open-source project team.
1111

@@ -25,11 +25,11 @@ libraries (such as NumPy, SciPy or scikit-image) and Qt graphical user interface
2525

2626
DataLab is available as a **stand-alone** application (see for example our all-in-one Windows installer) or as an **addon to your Python-Qt application** thanks to advanced automation and embedding features.
2727

28-
## About the client
28+
## About this package
2929

30-
This repository contains the DataLab client, which is a Python package that can be used to interact with a DataLab server.
30+
DataLab Simple Client is a Python library that can be used to interact with a DataLab application (server).
3131

32-
This allows to run computations on a remote server, or/and to control the DataLab GUI from a third-party application.
32+
This allows to control DataLab application from a remote computer, or/and from a third-party application.
3333

3434
### Credits
3535

@@ -40,5 +40,5 @@ Copyrights and licensing:
4040

4141
### Dependencies and other installation methods
4242

43-
See [Installation](https://cdl_client.readthedocs.io/en/latest/installation.html)
43+
See [Installation](https://cdlclient.readthedocs.io/en/latest/installation.html)
4444
section in the documentation for more details.

cdl_client/__init__.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

cdlclient/__init__.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Licensed under the terms of the BSD 3-Clause
4+
# (see cdlclient/LICENSE for details)
5+
6+
"""
7+
DataLab Simple Client
8+
=====================
9+
10+
DataLab Simple Client (`cdlclient`) is a Python library providing a proxy to `DataLab`_
11+
application through XML-RPC protocol.
12+
13+
.. _DataLab: https://codra-ingenierie-informatique.github.io/DataLab/
14+
"""
15+
16+
from cdlclient.baseproxy import SimpleBaseProxy
17+
from cdlclient.remote import SimpleRemoteProxy
18+
19+
__version__ = "0.1.0"
20+
__docurl__ = "https://cdlclient.readthedocs.io/en/latest/"
21+
__homeurl__ = "https://github.com/Codra-Ingenierie-Informatique/DataLabSimpleClient/"
22+
__supporturl__ = (
23+
"https://github.com/Codra-Ingenierie-Informatique/DataLabSimpleClient/issues/new/choose"
24+
)
Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,13 @@
11
# -*- coding: utf-8 -*-
22
#
33
# Licensed under the terms of the BSD 3-Clause
4-
# (see cdl_client/LICENSE for details)
4+
# (see cdlclient/LICENSE for details)
55

66
"""
77
DataLab base proxy module
88
-------------------------
99
"""
1010

11-
# How to add a new method to the proxy:
12-
# -------------------------------------
13-
#
14-
# 1. Add the method to the AbstractCDLControl class, as an abstract method
15-
#
16-
# 2a. If the method requires any data conversion to get through the XML-RPC layer,
17-
# implement the method in both CDLProxy and RemoteClient classes
18-
#
19-
# 2b. If the method does not require any data conversion, implement the method
20-
# directly in the BaseProxy class, so that it is available to both CDLProxy
21-
# and RemoteClient classes without any code duplication
22-
#
23-
# 3. Implement the method in the CDLMainWindow class
24-
#
25-
# 4. Implement the method in the RemoteServer class (it will be automatically
26-
# registered as an XML-RPC method, like all methods of AbstractCDLControl)
27-
2811
from __future__ import annotations
2912

3013
import abc
@@ -37,11 +20,14 @@
3720
if TYPE_CHECKING:
3821
from cdl.core.gui.main import CDLMainWindow
3922

40-
from cdl_client.remote import ServerProxy
23+
from cdlclient.remote import ServerProxy
4124

4225

43-
class AbstractCDLControl(abc.ABC):
44-
"""Abstract base class for controlling DataLab (main window or remote server)"""
26+
class SimpleAbstractCDLControl(abc.ABC):
27+
"""Simple abstract base class for controlling DataLab
28+
29+
This is a subset of DataLab's AbstractCDLControl, with only the methods that do not
30+
require DataLab object model to be implemented."""
4531

4632
@classmethod
4733
def get_public_methods(cls) -> list[str]:
@@ -329,17 +315,20 @@ def compute_func(param: gds.DataSet | None = None) -> gds.DataSet:
329315
raise AttributeError(f"DataLab has no compute function '{name}'")
330316

331317

332-
class BaseProxy(AbstractCDLControl, metaclass=abc.ABCMeta):
333-
"""Common base class for DataLab proxies
318+
class SimpleBaseProxy(SimpleAbstractCDLControl, metaclass=abc.ABCMeta):
319+
"""Simple common base class for DataLab proxies
320+
321+
This is a subset of DataLab's BaseProxy, with only the methods that do not require
322+
DataLab object model to be implemented.
334323
335324
Args:
336-
cdl_client (CDLMainWindow | ServerProxy | None): CDLMainWindow instance or
325+
cdlclient (CDLMainWindow | ServerProxy | None): CDLMainWindow instance or
337326
ServerProxy instance. If None, then the proxy implementation will
338-
have to set it later (e.g. see RemoteClient).
327+
have to set it later (e.g. see SimpleRemoteProxy).
339328
"""
340329

341-
def __init__(self, cdl_client: CDLMainWindow | ServerProxy | None = None) -> None:
342-
self._cdl = cdl_client
330+
def __init__(self, cdlclient: CDLMainWindow | ServerProxy | None = None) -> None:
331+
self._cdl = cdlclient
343332

344333
def get_version(self) -> str:
345334
"""Return DataLab version.
Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22
#
33
# Licensed under the terms of the BSD 3-Clause
4-
# (see cdl_client/LICENSE for details)
4+
# (see cdlclient/LICENSE for details)
55

66
"""
77
DataLab remote control
@@ -10,7 +10,8 @@
1010
This module provides utilities to control DataLab from a Python script (e.g. with
1111
Spyder) or from a Jupyter notebook.
1212
13-
The :class:`RemoteClient` class provides the main interface to DataLab XML-RPC server.
13+
The :class:`SimpleRemoteProxy` class provides the main interface
14+
to DataLab XML-RPC server.
1415
"""
1516

1617
from __future__ import annotations
@@ -30,7 +31,7 @@
3031
from guidata.env import execenv
3132
from guidata.userconfig import get_config_basedir
3233

33-
from cdl_client.baseproxy import BaseProxy
34+
from cdlclient.baseproxy import SimpleBaseProxy
3435

3536
# pylint: disable=invalid-name # Allows short reference names like x, y, ...
3637
# pylint: disable=duplicate-code
@@ -119,8 +120,8 @@ def json_to_dataset(param_data: list[str]) -> gds.DataSet:
119120

120121
# === Python 2.7 client side:
121122
#
122-
# # See doc/remotecontrol_py27.py for an almost complete Python 2.7
123-
# # implementation of RemoteClient class
123+
# # See DataLab's doc/remotecontrol_py27.py for an almost complete Python 2.7
124+
# # implementation of SimpleRemoteProxy class
124125
#
125126
# import io
126127
# from xmlrpclib import ServerProxy, Binary
@@ -135,10 +136,6 @@ def json_to_dataset(param_data: list[str]) -> gds.DataSet:
135136
# s.add_image("toto", array_to_binary(data))
136137

137138

138-
class CDLConnectionError(Exception):
139-
"""Error when trying to connect to DataLab XML-RPC server"""
140-
141-
142139
def get_cdl_xmlrpc_port():
143140
"""Return DataLab current XML-RPC port"""
144141
if sys.platform == "win32" and "HOME" in os.environ:
@@ -149,7 +146,7 @@ def get_cdl_xmlrpc_port():
149146
try:
150147
return ini.get("main", "rpc_server_port")
151148
except (cp.NoSectionError, cp.NoOptionError) as exc:
152-
raise CDLConnectionError("DataLab has not yet been executed") from exc
149+
raise ConnectionRefusedError("DataLab has not yet been executed") from exc
153150

154151

155152
def items_to_json(items: list) -> str | None:
@@ -170,16 +167,19 @@ def items_to_json(items: list) -> str | None:
170167
return None
171168

172169

173-
class RemoteClient(BaseProxy):
170+
class SimpleRemoteProxy(SimpleBaseProxy):
174171
"""Object representing a proxy/client to DataLab XML-RPC server.
175172
This object is used to call DataLab functions from a Python script.
176173
174+
This is a subset of DataLab's `RemoteClient` class, with only the methods
175+
that do not require DataLab object model to be implemented.
176+
177177
Examples:
178-
Here is a simple example of how to use RemoteClient in a Python script
178+
Here is a simple example of how to use SimpleRemoteProxy in a Python script
179179
or in a Jupyter notebook:
180180
181-
>>> from cdl_client.remotecontrol import RemoteClient
182-
>>> proxy = RemoteClient()
181+
>>> from cdlclient import SimpleRemoteProxy
182+
>>> proxy = SimpleRemoteProxy()
183183
>>> proxy.connect()
184184
Connecting to DataLab XML-RPC server...OK (port: 28867)
185185
>>> proxy.get_version()
@@ -189,9 +189,9 @@ class RemoteClient(BaseProxy):
189189
>>> proxy.get_object_titles()
190190
['toto']
191191
>>> proxy.get_object_from_title("toto")
192-
<cdl_client.model.signal.SignalObj at 0x7f7f1c0b4a90>
192+
<cdlclient.model.signal.SignalObj at 0x7f7f1c0b4a90>
193193
>>> proxy.get_object(0)
194-
<cdl_client.model.signal.SignalObj at 0x7f7f1c0b4a90>
194+
<cdlclient.model.signal.SignalObj at 0x7f7f1c0b4a90>
195195
>>> proxy.get_object(0).data
196196
array([1., 2., 3.])
197197
"""
@@ -209,7 +209,7 @@ def __connect_to_server(self, port: str | None = None) -> None:
209209
the port is automatically retrieved from DataLab configuration.
210210
211211
Raises:
212-
CDLConnectionError: DataLab is currently not running
212+
ConnectionRefusedError: DataLab is currently not running
213213
"""
214214
if port is None:
215215
port = get_xmlrpcport_from_env()
@@ -220,7 +220,7 @@ def __connect_to_server(self, port: str | None = None) -> None:
220220
try:
221221
self.get_version()
222222
except ConnectionRefusedError as exc:
223-
raise CDLConnectionError("DataLab is currently not running") from exc
223+
raise ConnectionRefusedError("DataLab is currently not running") from exc
224224

225225
def connect(
226226
self,
@@ -237,7 +237,7 @@ def connect(
237237
retries (int | None): Number of retries. Defaults to 10.
238238
239239
Raises:
240-
CDLConnectionError: Unable to connect to DataLab
240+
ConnectionRefusedError: Unable to connect to DataLab
241241
ValueError: Invalid timeout (must be >= 0.0)
242242
ValueError: Invalid number of retries (must be >= 1)
243243
"""
@@ -252,11 +252,11 @@ def connect(
252252
try:
253253
self.__connect_to_server(port=port)
254254
break
255-
except CDLConnectionError:
255+
except ConnectionRefusedError:
256256
time.sleep(timeout / retries)
257257
else:
258258
execenv.print("KO")
259-
raise CDLConnectionError("Unable to connect to DataLab")
259+
raise ConnectionRefusedError("Unable to connect to DataLab")
260260
execenv.print(f"OK (port: {self.port})")
261261

262262
def disconnect(self) -> None:

0 commit comments

Comments
 (0)