Skip to content

Commit c7f4408

Browse files
committed
DS classes
1 parent 00410d0 commit c7f4408

4 files changed

Lines changed: 78 additions & 11 deletions

File tree

datashield/interface.py

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ class DSConnection:
3232
"""
3333
Connection class to a DataSHIELD server.
3434
"""
35-
35+
36+
#
37+
# Content listing
38+
#
39+
3640
def list_tables(self) -> list:
3741
"""
3842
List available table names from the data repository.
@@ -61,9 +65,13 @@ def has_resource(self, name: str) -> bool:
6165
"""
6266
raise NotImplementedError("DSConnection function not available")
6367

68+
#
69+
# Assign
70+
#
71+
6472
def assign_table(self, symbol: str, table: str, variables: list = None,
6573
missings: bool = False, identifiers: str = None,
66-
id_name: str = None, asynchronous: bool = True) -> None:
74+
id_name: str = None, asynchronous: bool = True) -> DSResult:
6775
"""
6876
Assign a data table from the data repository to a symbol in the DataSHIELD R session.
6977
@@ -73,7 +81,7 @@ def assign_table(self, symbol: str, table: str, variables: list = None,
7381
"""
7482
raise NotImplementedError("DSConnection function not available")
7583

76-
def assign_resource(self, symbol: str, resource: str, asynchronous: bool = True) -> None:
84+
def assign_resource(self, symbol: str, resource: str, asynchronous: bool = True) -> DSResult:
7785
"""
7886
Assign a resource from the data repository to a symbol in the DataSHIELD R session.
7987
@@ -83,7 +91,7 @@ def assign_resource(self, symbol: str, resource: str, asynchronous: bool = True)
8391
"""
8492
raise NotImplementedError("DSConnection function not available")
8593

86-
def assign_expr(self, symbol: str, expr: str, asynchronous: bool = True) -> None:
94+
def assign_expr(self, symbol: str, expr: str, asynchronous: bool = True) -> DSResult:
8795
"""
8896
Assign the result of the evaluation of an expression to a symbol in the DataSHIELD R session.
8997
@@ -93,6 +101,10 @@ def assign_expr(self, symbol: str, expr: str, asynchronous: bool = True) -> None
93101
"""
94102
raise NotImplementedError("DSConnection function not available")
95103

104+
#
105+
# Aggregate
106+
#
107+
96108
def aggregate(self, expr: str, asynchronous: bool = True) -> DSResult:
97109
"""
98110
Aggregate some data from the DataSHIELD R session using a valid R expression. The
@@ -103,6 +115,10 @@ def aggregate(self, expr: str, asynchronous: bool = True) -> DSResult:
103115
"""
104116
raise NotImplementedError("DSConnection function not available")
105117

118+
#
119+
# Symbols
120+
#
121+
106122
def list_symbols(self) -> list:
107123
"""
108124
After assignments have been performed, some symbols live in the DataSHIELD R session on the server side.
@@ -116,7 +132,11 @@ def rm_symbol(self, name: str) -> None:
116132
:param name: The name of symbol to remove
117133
"""
118134
raise NotImplementedError("DSConnection function not available")
119-
135+
136+
#
137+
# DataSHIELD config
138+
#
139+
120140
def list_profiles(self) -> list:
121141
"""
122142
List available DataSHIELD profile names in the data repository.
@@ -136,7 +156,11 @@ def list_packages(self) -> list:
136156
Get the list of DataSHIELD packages with their version, that have been configured on the remote data repository.
137157
"""
138158
raise NotImplementedError("DSConnection function not available")
139-
159+
160+
#
161+
# Workspaces
162+
#
163+
140164
def list_workspaces(self) -> list:
141165
"""
142166
Get the list of DataSHIELD workspaces, that have been saved on the remote data repository.
@@ -169,7 +193,11 @@ def rm_workspace(self, name: str) -> list:
169193
"""
170194
raise NotImplementedError("DSConnection function not available")
171195

172-
def is_async(self) -> bool:
196+
#
197+
# Utils
198+
#
199+
200+
def is_async(self) -> dict:
173201
"""
174202
When a DSResult object is returned on aggregation or assignment operation,
175203
the raw result can be accessed asynchronously, allowing parallelization of DataSHIELD calls
@@ -179,7 +207,7 @@ def is_async(self) -> bool:
179207
"""
180208
raise NotImplementedError("DSConnection function not available")
181209

182-
def keep_alive(self) -> bool:
210+
def keep_alive(self) -> None:
183211
"""
184212
As the DataSHIELD sessions are working in parallel, this function helps at keeping
185213
idle connections alive while others are working. Any communication failure must
@@ -200,12 +228,13 @@ class DSDriver:
200228
"""
201229

202230
@classmethod
203-
def new_connection(cls, name: str, args: dict, restore: str = None) -> DSConnection:
231+
def new_connection(cls, name: str, args: dict, profile: str = "default", restore: str = None) -> DSConnection:
204232
"""
205233
Creates a new connection
206234
207235
:param name: The DataSHIELD server name
208236
:param args: The connection arguments, as a dictionary
237+
:param profile: The DataSHIELD profile name to be used
209238
:param restore: The workspace name to be restored
210239
"""
211240
raise NotImplementedError("DSConnection function not available")

datashield/utils.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
DataSHIELD utils.
3+
"""
4+
5+
class DSLoginBuilder:
6+
"""
7+
Helper class to formalize DataSHIELD login arguments for a set of servers.
8+
"""
9+
10+
def __init__(self):
11+
self.items = list()
12+
13+
def add(self, name: str, url: str, user: str = None, password: str = None, token: str = None):
14+
self.items.append({
15+
'name': name,
16+
'url': url,
17+
'user': user,
18+
'password': password,
19+
'token': token
20+
})
21+
return self
22+
23+
def build(self):
24+
return self.items

poetry.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/test_utils.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from datashield.utils import DSLoginBuilder
2+
3+
def test_logins():
4+
builder = DSLoginBuilder().add("server1", "https://opal-demo.obba.org", "dsuser", "P@ssw0rd").add("server2", "https://demo.datashield.org", token = "1234abcd")
5+
logins = builder.build()
6+
assert len(logins) == 2
7+
assert logins[0]["name"] == "server1"
8+
assert logins[0]["user"] is not None
9+
assert logins[0]["password"] is not None
10+
assert logins[0]["token"] is None
11+
assert logins[1]["name"] == "server2"
12+
assert logins[1]["user"] is None
13+
assert logins[1]["password"] is None
14+
assert logins[1]["token"] is not None

0 commit comments

Comments
 (0)