Skip to content

Commit 3a2e8a7

Browse files
committed
Code cleaning and profile added to login builder
1 parent c7f4408 commit 3a2e8a7

File tree

3 files changed

+39
-36
lines changed

3 files changed

+39
-36
lines changed

datashield/interface.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ def is_completed(self) -> bool:
1717
wait for the completion, immediate response is expected. Once the result is
1818
identified as being completed, the raw result the operation can be get directly.
1919
"""
20-
raise NotImplementedError("DSResult function not available")
20+
raise NotImplementedError('DSResult function not available')
2121

2222
def fetch(self) -> any:
2323
"""
2424
Wait for the result to be available and fetch the result from a previous assignment or aggregation operation that may have been
2525
run asynchronously, in which case it is a one-shot call. When the assignment or aggregation operation was not asynchronous,
2626
the result is wrapped in the object and can be fetched multiple times.
2727
"""
28-
raise NotImplementedError("DSResult function not available")
28+
raise NotImplementedError('DSResult function not available')
2929

3030

3131
class DSConnection:
@@ -41,29 +41,29 @@ def list_tables(self) -> list:
4141
"""
4242
List available table names from the data repository.
4343
"""
44-
raise NotImplementedError("DSConnection function not available")
44+
raise NotImplementedError('DSConnection function not available')
4545

4646
def has_table(self, name: str) -> bool:
4747
"""
4848
Check whether a table with provided name exists in the data repository.
4949
5050
:param name: The name of the table to check
5151
"""
52-
raise NotImplementedError("DSConnection function not available")
52+
raise NotImplementedError('DSConnection function not available')
5353

5454
def list_resources(self) -> list:
5555
"""
5656
List available resource names from the data repository.
5757
"""
58-
raise NotImplementedError("DSConnection function not available")
58+
raise NotImplementedError('DSConnection function not available')
5959

6060
def has_resource(self, name: str) -> bool:
6161
"""
6262
Check whether a resource with provided name exists in the data repository.
6363
6464
:param name: The name of the resource to check
6565
"""
66-
raise NotImplementedError("DSConnection function not available")
66+
raise NotImplementedError('DSConnection function not available')
6767

6868
#
6969
# Assign
@@ -79,7 +79,7 @@ def assign_table(self, symbol: str, table: str, variables: list = None,
7979
:param table: The name of the table to assign
8080
:param asynchronous: Whether the operation is asynchronous (if supported by the DataSHIELD server)
8181
"""
82-
raise NotImplementedError("DSConnection function not available")
82+
raise NotImplementedError('DSConnection function not available')
8383

8484
def assign_resource(self, symbol: str, resource: str, asynchronous: bool = True) -> DSResult:
8585
"""
@@ -89,7 +89,7 @@ def assign_resource(self, symbol: str, resource: str, asynchronous: bool = True)
8989
:param resource: The name of the resource to assign
9090
:param asynchronous: Whether the operation is asynchronous (if supported by the DataSHIELD server)
9191
"""
92-
raise NotImplementedError("DSConnection function not available")
92+
raise NotImplementedError('DSConnection function not available')
9393

9494
def assign_expr(self, symbol: str, expr: str, asynchronous: bool = True) -> DSResult:
9595
"""
@@ -99,7 +99,7 @@ def assign_expr(self, symbol: str, expr: str, asynchronous: bool = True) -> DSRe
9999
:param expr: The R expression to evaluate and which result will be assigned
100100
:param asynchronous: Whether the operation is asynchronous (if supported by the DataSHIELD server)
101101
"""
102-
raise NotImplementedError("DSConnection function not available")
102+
raise NotImplementedError('DSConnection function not available')
103103

104104
#
105105
# Aggregate
@@ -113,7 +113,7 @@ def aggregate(self, expr: str, asynchronous: bool = True) -> DSResult:
113113
:param expr: The R expression to evaluate and which result will be returned
114114
:param asynchronous: Whether the operation is asynchronous (if supported by the DataSHIELD server)
115115
"""
116-
raise NotImplementedError("DSConnection function not available")
116+
raise NotImplementedError('DSConnection function not available')
117117

118118
#
119119
# Symbols
@@ -123,15 +123,15 @@ def list_symbols(self) -> list:
123123
"""
124124
After assignments have been performed, some symbols live in the DataSHIELD R session on the server side.
125125
"""
126-
raise NotImplementedError("DSConnection function not available")
126+
raise NotImplementedError('DSConnection function not available')
127127

128128
def rm_symbol(self, name: str) -> None:
129129
"""
130130
After symbol removal, the data identified by the symbol will not be accessible in the DataSHIELD R session on the server side.
131131
132132
:param name: The name of symbol to remove
133133
"""
134-
raise NotImplementedError("DSConnection function not available")
134+
raise NotImplementedError('DSConnection function not available')
135135

136136
#
137137
# DataSHIELD config
@@ -141,21 +141,21 @@ def list_profiles(self) -> list:
141141
"""
142142
List available DataSHIELD profile names in the data repository.
143143
"""
144-
raise NotImplementedError("DSConnection function not available")
144+
raise NotImplementedError('DSConnection function not available')
145145

146146
def list_methods(self, type: str = "aggregate") -> list:
147147
"""
148148
Get the list of DataSHIELD methods that have been configured on the remote data repository.
149149
150150
:param type: The type of method, either "aggregate" (default) or "assign"
151151
"""
152-
raise NotImplementedError("DSConnection function not available")
152+
raise NotImplementedError('DSConnection function not available')
153153

154154
def list_packages(self) -> list:
155155
"""
156156
Get the list of DataSHIELD packages with their version, that have been configured on the remote data repository.
157157
"""
158-
raise NotImplementedError("DSConnection function not available")
158+
raise NotImplementedError('DSConnection function not available')
159159

160160
#
161161
# Workspaces
@@ -165,15 +165,15 @@ def list_workspaces(self) -> list:
165165
"""
166166
Get the list of DataSHIELD workspaces, that have been saved on the remote data repository.
167167
"""
168-
raise NotImplementedError("DSConnection function not available")
168+
raise NotImplementedError('DSConnection function not available')
169169

170170
def save_workspace(self, name: str) -> list:
171171
"""
172172
Save the DataSHIELD R session in a workspace on the remote data repository.
173173
174174
:param name: The name of the workspace
175175
"""
176-
raise NotImplementedError("DSConnection function not available")
176+
raise NotImplementedError('DSConnection function not available')
177177

178178
def restore_workspace(self, name: str) -> list:
179179
"""
@@ -182,7 +182,7 @@ def restore_workspace(self, name: str) -> list:
182182
183183
:param name: The name of the workspace
184184
"""
185-
raise NotImplementedError("DSConnection function not available")
185+
raise NotImplementedError('DSConnection function not available')
186186

187187
def rm_workspace(self, name: str) -> list:
188188
"""
@@ -191,7 +191,7 @@ def rm_workspace(self, name: str) -> list:
191191
192192
:param name: The name of the workspace
193193
"""
194-
raise NotImplementedError("DSConnection function not available")
194+
raise NotImplementedError('DSConnection function not available')
195195

196196
#
197197
# Utils
@@ -205,21 +205,21 @@ def is_async(self) -> dict:
205205
aggregation operation ('aggregate'), table assignment operation ('assign_table'),
206206
resource assignment operation ('assign_resource') and expression assignment operation ('assign_expr').
207207
"""
208-
raise NotImplementedError("DSConnection function not available")
208+
raise NotImplementedError('DSConnection function not available')
209209

210210
def keep_alive(self) -> None:
211211
"""
212212
As the DataSHIELD sessions are working in parallel, this function helps at keeping
213213
idle connections alive while others are working. Any communication failure must
214214
be silently processed.
215215
"""
216-
raise NotImplementedError("DSConnection function not available")
216+
raise NotImplementedError('DSConnection function not available')
217217

218218
def disconnect(self) -> None:
219219
"""
220220
This closes the connection, discards all pending work, and frees resources (e.g., memory, sockets).
221221
"""
222-
raise NotImplementedError("DSConnection function not available")
222+
raise NotImplementedError('DSConnection function not available')
223223

224224

225225
class DSDriver:
@@ -237,7 +237,7 @@ def new_connection(cls, name: str, args: dict, profile: str = "default", restore
237237
:param profile: The DataSHIELD profile name to be used
238238
:param restore: The workspace name to be restored
239239
"""
240-
raise NotImplementedError("DSConnection function not available")
240+
raise NotImplementedError('DSConnection function not available')
241241

242242
@classmethod
243243
def load_class(cls, name: str) -> any:
@@ -247,7 +247,7 @@ def load_class(cls, name: str) -> any:
247247
:param name: The driver class name
248248
:return The class of the driver on which the ``new_connection()`` function will be called
249249
"""
250-
names = name.split(".")
250+
names = name.split('.')
251251
className = names.pop()
252-
moduleName = ".".join(names)
252+
moduleName = '.'.join(names)
253253
return getattr(importlib.import_module(moduleName), className)

datashield/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ class DSLoginBuilder:
1010
def __init__(self):
1111
self.items = list()
1212

13-
def add(self, name: str, url: str, user: str = None, password: str = None, token: str = None):
13+
def add(self, name: str, url: str, user: str = None, password: str = None, token: str = None, profile: str = 'default'):
1414
self.items.append({
1515
'name': name,
1616
'url': url,
1717
'user': user,
1818
'password': password,
19-
'token': token
19+
'token': token,
20+
'profile': profile
2021
})
2122
return self
2223

tests/test_utils.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
from datashield.utils import DSLoginBuilder
22

33
def test_logins():
4-
builder = DSLoginBuilder().add("server1", "https://opal-demo.obba.org", "dsuser", "P@ssw0rd").add("server2", "https://demo.datashield.org", token = "1234abcd")
4+
builder = DSLoginBuilder().add('server1', 'https://opal-demo.obba.org', 'dsuser', 'P@ssw0rd').add('server2', 'https://demo.datashield.org', token = '1234abcd', profile = 'omics')
55
logins = builder.build()
66
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
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[0]['profile'] == 'default'
12+
assert logins[1]['name'] == 'server2'
13+
assert logins[1]['user'] is None
14+
assert logins[1]['password'] is None
15+
assert logins[1]['token'] is not None
16+
assert logins[1]['profile'] == 'omics'

0 commit comments

Comments
 (0)