pybioos 0.0.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pybioos might be problematic. Click here for more details.
- bioos/__about__.py +4 -0
- bioos/__init__.py +1 -0
- bioos/bioos.py +90 -0
- bioos/bioos_workflow.py +284 -0
- bioos/config.py +147 -0
- bioos/errors.py +89 -0
- bioos/internal/__init__.py +1 -0
- bioos/internal/tos.py +306 -0
- bioos/log.py +125 -0
- bioos/models/__init__.py +1 -0
- bioos/models/models.py +13 -0
- bioos/resource/__init__.py +1 -0
- bioos/resource/data_models.py +157 -0
- bioos/resource/files.py +229 -0
- bioos/resource/utility.py +45 -0
- bioos/resource/workflows.py +590 -0
- bioos/resource/workspaces.py +123 -0
- bioos/service/BioOsService.py +191 -0
- bioos/service/__init__.py +1 -0
- bioos/service/api.py +291 -0
- bioos/service/config.py +37 -0
- bioos/tests/__init__.py +0 -0
- bioos/tests/base.py +21 -0
- bioos/tests/bioos.py +43 -0
- bioos/tests/data_models.py +259 -0
- bioos/tests/files.py +174 -0
- bioos/tests/utils.py +68 -0
- bioos/tests/workflows.py +287 -0
- bioos/tests/workspaces.py +115 -0
- bioos/utils/__init__.py +0 -0
- bioos/utils/common_tools.py +57 -0
- bioos/utils/workflows.py +2 -0
- pybioos-0.0.3.dist-info/LICENSE +21 -0
- pybioos-0.0.3.dist-info/METADATA +24 -0
- pybioos-0.0.3.dist-info/RECORD +38 -0
- pybioos-0.0.3.dist-info/WHEEL +5 -0
- pybioos-0.0.3.dist-info/entry_points.txt +2 -0
- pybioos-0.0.3.dist-info/top_level.txt +1 -0
bioos/tests/workflows.py
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import time
|
|
2
|
+
from unittest import mock
|
|
3
|
+
from unittest.mock import patch
|
|
4
|
+
|
|
5
|
+
import pandas
|
|
6
|
+
from pandas import DataFrame
|
|
7
|
+
|
|
8
|
+
from bioos import bioos
|
|
9
|
+
from bioos.errors import ConflictError
|
|
10
|
+
from bioos.service.BioOsService import BioOsService
|
|
11
|
+
from bioos.tests.base import BaseInit
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class TestWorkflows(BaseInit):
|
|
15
|
+
cluster_id = "default"
|
|
16
|
+
|
|
17
|
+
workflow_name = "hello-test"
|
|
18
|
+
workflow_id = "fake_workflow_id"
|
|
19
|
+
|
|
20
|
+
data_model_name = "my_entity"
|
|
21
|
+
data_model_id = "fake_data_model_id"
|
|
22
|
+
|
|
23
|
+
submission_id = "fake_submission_id"
|
|
24
|
+
run_id = "fake_run_id"
|
|
25
|
+
|
|
26
|
+
list_workspace_val = {
|
|
27
|
+
'Items':
|
|
28
|
+
[{'ID': BaseInit.workspace_id, 'Name': 'test-gqm',
|
|
29
|
+
'Description': 'test-gqm', 'CreateTime': 1661326698,
|
|
30
|
+
'UpdateTime': 1661326698, 'OwnerName': 'test',
|
|
31
|
+
'CoverDownloadURL':
|
|
32
|
+
'https://fake.tos-s3-cn-beijing.volces.com/template-cover/pic7.png?XXXXXXXXXXXX',
|
|
33
|
+
'Role': 'Admin', 'S3Bucket': 'bioos-dev-fake-workspace'}],
|
|
34
|
+
'PageNumber': 1, 'PageSize': 10, 'TotalCount': 1}
|
|
35
|
+
|
|
36
|
+
list_workflows_val = {'Items': [
|
|
37
|
+
{'ID': workflow_id, 'Name': workflow_name, 'Description': '[dockstore]',
|
|
38
|
+
'CreateTime': 1670929870, 'UpdateTime': 1671032374, 'Language': 'WDL',
|
|
39
|
+
'Source': 'https://github.com/fake/hello.git', 'Tag': 'main',
|
|
40
|
+
'MainWorkflowPath': 'hello.wdl',
|
|
41
|
+
'Status': {'Phase': 'Failed',
|
|
42
|
+
'Message': 'job failed: Reason=BackoffLimitExceeded, '
|
|
43
|
+
'Message=Job has reached the specified backoff limit; '
|
|
44
|
+
'failed to getJobLogs: invalid number of pods: 0'}}
|
|
45
|
+
], 'Total': 1}
|
|
46
|
+
|
|
47
|
+
list_data_models_val = {'Total': 1, 'Items': [
|
|
48
|
+
{'ID': data_model_id, 'Name': data_model_name, 'RowCount': 162, 'Type': 'normal'},
|
|
49
|
+
]}
|
|
50
|
+
|
|
51
|
+
workflow_env_info = {
|
|
52
|
+
'Items':
|
|
53
|
+
[{'ClusterInfo':
|
|
54
|
+
{'ID': 'default',
|
|
55
|
+
'Name': 'Volcengine Container Cluster',
|
|
56
|
+
'Status': 'Running',
|
|
57
|
+
'StartTime': 1668596478,
|
|
58
|
+
'Description': 'Default Volcengine Container Cluster',
|
|
59
|
+
'Bound': True,
|
|
60
|
+
'Public': True,
|
|
61
|
+
'ExternalConfig': {
|
|
62
|
+
'WESEndpoint': 'http://localhost:8080/ga4gh/wes/v1',
|
|
63
|
+
'JupyterhubEndpoint': 'http://jupyterhub.fake.com/jupyterhub',
|
|
64
|
+
'JupyterhubJWTSecret': '',
|
|
65
|
+
'ResourceScheduler': 'Kubernetes',
|
|
66
|
+
'Filesystem': 'tos'}},
|
|
67
|
+
'Type': 'workflow', 'BindTime': 1676534060}], 'TotalCount': 1
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
list_submission_val = {
|
|
71
|
+
'Items': [{'ID': 'fake_submission_id', 'Name': 'hello-history-2022-12-21-16-54-29',
|
|
72
|
+
'Description': 'gqm-test-sdk', 'Status': 'Failed',
|
|
73
|
+
'RunStatus': {'Count': 3, 'Succeeded': 0, 'Failed': 3,
|
|
74
|
+
'Running': 0}, 'StartTime': 1671612870,
|
|
75
|
+
'FinishTime': 1671613042, 'Duration': 172, 'WorkflowID':
|
|
76
|
+
'fcegt1vleig4f5465sofg', 'ClusterID': 'default',
|
|
77
|
+
'DataModelID': 'fake_data_model_id',
|
|
78
|
+
'Inputs': '{"testname.hello.name":"this.date"}',
|
|
79
|
+
'Outputs': '{"testname.hello.response":"this.response1"}',
|
|
80
|
+
'ExposedOptions': {'ReadFromCache': False,
|
|
81
|
+
'ExecutionRootDir': 's3://bioos-dev-fake-workspace'},
|
|
82
|
+
'OwnerName': 'test'}], 'PageNumber': 1, 'PageSize': 10, 'TotalCount': 1}
|
|
83
|
+
|
|
84
|
+
finished_list_runs_val = {'Total': 1, 'Items': [
|
|
85
|
+
{'ID': run_id, 'DataEntityRowID': 'your-sample-3-id', 'Status': 'Failed',
|
|
86
|
+
'StartTime': 1671612870, 'FinishTime': 1671613042, 'Duration': 172,
|
|
87
|
+
'SubmissionID': 'fake_submission_id',
|
|
88
|
+
'EngineRunID': 'd0da2939-8d12-4ba3-9872-529677a39da9',
|
|
89
|
+
'Inputs': '{"testname.hello.name":"01/01/2022"}', 'Outputs': '',
|
|
90
|
+
'TaskStatus': {'Succeeded': 0, 'Failed': 1, 'Running': 0},
|
|
91
|
+
'Log': 's3://bioos-dev-fake-workspace/analysis/fake_submission_id'
|
|
92
|
+
'/workflow.d0da2939-8d12-4ba3-9872-529677a39da9.log',
|
|
93
|
+
'Message': 'workflow run failed: [{"causedBy":[{"causedBy":[],"message":"Task '
|
|
94
|
+
'testname.hello:NA:1 failed for unknown reason: FailedOrError"}],'
|
|
95
|
+
'"message":"Workflow failed"}]'
|
|
96
|
+
}]}
|
|
97
|
+
|
|
98
|
+
list_run_val = {'Total': 1, 'Items': [
|
|
99
|
+
{'ID': run_id, 'DataEntityRowID': 'your-sample-3-id', 'Status': 'Running',
|
|
100
|
+
'StartTime': 1671612870, 'Duration': 0, 'SubmissionID': 'fake_submission_id',
|
|
101
|
+
'EngineRunID': None, 'Inputs': '{"testname.hello.name":"01/01/2022"}', 'Outputs': ''}]}
|
|
102
|
+
|
|
103
|
+
list_tasks_val = {'Total': 0, 'Items': []}
|
|
104
|
+
finished_list_tasks_val = {'Total': 1, 'Items': [
|
|
105
|
+
{'Name': 'testname.hello', 'RunID': run_id, 'Status': 'Failed', 'StartTime': 1671612876,
|
|
106
|
+
'FinishTime': 1671613037, 'Duration': 161,
|
|
107
|
+
'Log': 's3://bioos-dev-fake-workspace/analysis/fake_submission_id/testname'
|
|
108
|
+
'/d0da2939-8d12-4ba3-9872-529677a39da9/call-hello/execution/log',
|
|
109
|
+
'Stdout': 's3://bioos-dev-fake-workspace/analysis/fake_submission_id/testname'
|
|
110
|
+
'/d0da2939-8d12-4ba3-9872-529677a39da9/call-hello/execution/stdout',
|
|
111
|
+
'Stderr': 's3://bioos-dev-fake-workspace/analysis/fake_submission_id/testname'
|
|
112
|
+
'/d0da2939-8d12-4ba3-9872-529677a39da9/call-hello/execution/stderr'}]}
|
|
113
|
+
|
|
114
|
+
def __init__(self, *args, **kwargs):
|
|
115
|
+
super(TestWorkflows, self).__init__(*args, **kwargs)
|
|
116
|
+
ws = bioos.workspace(self.workspace_id)
|
|
117
|
+
with patch.object(BioOsService, "list_workspaces",
|
|
118
|
+
return_value=self.list_workspace_val):
|
|
119
|
+
with patch.object(BioOsService, "list_workflows",
|
|
120
|
+
return_value=self.list_workflows_val):
|
|
121
|
+
self.workflows = ws.workflows
|
|
122
|
+
self.workflow = ws.workflow(self.workflow_name)
|
|
123
|
+
# XXX: wait for a while to make cache overdue
|
|
124
|
+
time.sleep(2)
|
|
125
|
+
|
|
126
|
+
def test_workflows_repr(self):
|
|
127
|
+
with patch.object(BioOsService, "list_workflows",
|
|
128
|
+
return_value=self.list_workflows_val) as success_list_workflows:
|
|
129
|
+
with patch.object(BioOsService, "list_cluster",
|
|
130
|
+
return_value=self.workflow_env_info) as success_list_cluster:
|
|
131
|
+
# makes no call
|
|
132
|
+
self.workflows
|
|
133
|
+
# call list_workflows once and list_cluster twice
|
|
134
|
+
repr(self.workflows)
|
|
135
|
+
# make another call of list_workflows
|
|
136
|
+
list_res = self.workflows.list()
|
|
137
|
+
pandas.testing.assert_frame_equal(list_res, DataFrame.from_records([
|
|
138
|
+
{'ID': self.workflow_id, 'Name': self.workflow_name,
|
|
139
|
+
'Description': '[dockstore]',
|
|
140
|
+
'CreateTime': pandas.to_datetime(1670929870,
|
|
141
|
+
unit='ms',
|
|
142
|
+
origin=pandas.Timestamp('2018-07-01')),
|
|
143
|
+
'UpdateTime': pandas.to_datetime(1671032374,
|
|
144
|
+
unit='ms',
|
|
145
|
+
origin=pandas.Timestamp('2018-07-01')),
|
|
146
|
+
'Language': 'WDL', 'Source': 'https://github.com/fake/hello.git',
|
|
147
|
+
'Tag': 'main', 'MainWorkflowPath': 'hello.wdl'}
|
|
148
|
+
]))
|
|
149
|
+
success_list_workflows.assert_has_calls([
|
|
150
|
+
mock.call({
|
|
151
|
+
'WorkspaceID': self.workspace_id,
|
|
152
|
+
'SortBy': 'CreateTime',
|
|
153
|
+
'PageSize': 0,
|
|
154
|
+
}),
|
|
155
|
+
mock.call({
|
|
156
|
+
'WorkspaceID': self.workspace_id,
|
|
157
|
+
'SortBy': 'CreateTime',
|
|
158
|
+
'PageSize': 0,
|
|
159
|
+
}),
|
|
160
|
+
])
|
|
161
|
+
success_list_cluster.assert_has_calls([
|
|
162
|
+
mock.call(params={
|
|
163
|
+
'Type': "workflow",
|
|
164
|
+
"ID": self.workspace_id
|
|
165
|
+
})
|
|
166
|
+
])
|
|
167
|
+
|
|
168
|
+
def test_import_and_delete(self):
|
|
169
|
+
with patch.object(BioOsService, "check_workflow",
|
|
170
|
+
return_value={'IsNameExist': False}) as success_check:
|
|
171
|
+
with patch.object(BioOsService, "create_workflow",
|
|
172
|
+
return_value={'ID': self.workflow_id}) as success_create:
|
|
173
|
+
workflow_id = self.workflows.import_workflow("https://github.com/fake/hello.git",
|
|
174
|
+
self.workflow_name, "WDL", "main",
|
|
175
|
+
"hello.wdl", "[dockstore]")
|
|
176
|
+
self.assertEqual(workflow_id, self.workflow_id)
|
|
177
|
+
success_check.assert_called_once_with({
|
|
178
|
+
"WorkspaceID": self.workspace_id,
|
|
179
|
+
"Name": self.workflow_name,
|
|
180
|
+
})
|
|
181
|
+
success_create.assert_called_once_with({
|
|
182
|
+
"WorkspaceID": self.workspace_id,
|
|
183
|
+
"Name": self.workflow_name,
|
|
184
|
+
"Description": "[dockstore]",
|
|
185
|
+
"Language": "WDL",
|
|
186
|
+
"Source": "https://github.com/fake/hello.git",
|
|
187
|
+
"Tag": "main",
|
|
188
|
+
"MainWorkflowPath": "hello.wdl",
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
with patch.object(BioOsService, "check_workflow",
|
|
192
|
+
return_value={'IsNameExist': True}) as success_check:
|
|
193
|
+
with patch.object(BioOsService, "create_workflow") as miss_create:
|
|
194
|
+
try:
|
|
195
|
+
self.workflows.import_workflow("https://github.com/fake/hello.git",
|
|
196
|
+
self.workflow_name, "WDL", "main", "hello.wdl",
|
|
197
|
+
"[dockstore]")
|
|
198
|
+
except ConflictError as e:
|
|
199
|
+
self.assertEqual(e.message, f"parameter 'name' conflicts: "
|
|
200
|
+
f"{self.workflow_name} already exists")
|
|
201
|
+
success_check.assert_called_once_with({
|
|
202
|
+
"WorkspaceID": self.workspace_id,
|
|
203
|
+
"Name": self.workflow_name,
|
|
204
|
+
})
|
|
205
|
+
miss_create.assert_not_called()
|
|
206
|
+
|
|
207
|
+
with patch.object(BioOsService, "delete_workflow") as success_delete:
|
|
208
|
+
with patch.object(BioOsService, "list_workflows",
|
|
209
|
+
return_value=self.list_workflows_val):
|
|
210
|
+
with patch.object(BioOsService, "list_cluster",
|
|
211
|
+
return_value=self.workflow_env_info):
|
|
212
|
+
self.workflows.delete(self.workflow_name)
|
|
213
|
+
|
|
214
|
+
success_delete.assert_called_once_with({
|
|
215
|
+
"WorkspaceID": self.workspace_id,
|
|
216
|
+
"ID": self.workflow_id
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
def test_submit(self):
|
|
220
|
+
with patch.object(BioOsService, "list_cluster",
|
|
221
|
+
return_value=self.workflow_env_info) as list_cluster:
|
|
222
|
+
with patch.object(BioOsService, "list_workflows",
|
|
223
|
+
return_value=self.list_workflows_val) as list_workflows:
|
|
224
|
+
with patch.object(BioOsService, "list_data_models",
|
|
225
|
+
return_value=self.list_data_models_val) as list_data_models:
|
|
226
|
+
with patch.object(BioOsService, "create_submission",
|
|
227
|
+
return_value={
|
|
228
|
+
'ID': self.submission_id}) as create_submission:
|
|
229
|
+
with patch.object(BioOsService, "list_submissions",
|
|
230
|
+
return_value=self.list_submission_val) as list_submissions:
|
|
231
|
+
with patch.object(BioOsService, "list_tasks",
|
|
232
|
+
return_value=self.list_tasks_val) as list_tasks:
|
|
233
|
+
with patch.object(BioOsService, "list_runs",
|
|
234
|
+
return_value=self.list_run_val) as list_runs:
|
|
235
|
+
runs = self.workflow.submit(
|
|
236
|
+
data_model_name=self.data_model_name,
|
|
237
|
+
row_ids=[
|
|
238
|
+
"your-sample-3-id"
|
|
239
|
+
],
|
|
240
|
+
inputs='{"testname.hello.name":"this.name1"}',
|
|
241
|
+
outputs='{"testname.hello.response":"this.response1"}',
|
|
242
|
+
submission_desc="gqm-test-sdk",
|
|
243
|
+
call_caching=False)
|
|
244
|
+
self.assertEqual(len(runs), 1)
|
|
245
|
+
run = runs[0]
|
|
246
|
+
self.assertEqual(run.submission, self.submission_id)
|
|
247
|
+
self.assertEqual(run.id, self.run_id)
|
|
248
|
+
list_cluster.assert_called_once()
|
|
249
|
+
list_workflows.assert_called_once_with({
|
|
250
|
+
'WorkspaceID': self.workspace_id,
|
|
251
|
+
'SortBy': 'CreateTime',
|
|
252
|
+
'PageSize': 0,
|
|
253
|
+
})
|
|
254
|
+
list_data_models.assert_has_calls([
|
|
255
|
+
mock.call({
|
|
256
|
+
'WorkspaceID': self.workspace_id
|
|
257
|
+
}), mock.call({
|
|
258
|
+
'WorkspaceID': self.workspace_id
|
|
259
|
+
})
|
|
260
|
+
])
|
|
261
|
+
# list_data_models.assert_called_once()
|
|
262
|
+
create_submission.assert_called_once()
|
|
263
|
+
# list_runs.assert_called_once()
|
|
264
|
+
list_submissions.assert_called_once()
|
|
265
|
+
list_tasks.assert_not_called()
|
|
266
|
+
list_runs.assert_has_calls([
|
|
267
|
+
mock.call({
|
|
268
|
+
'WorkspaceID': self.workspace_id,
|
|
269
|
+
'SubmissionID': self.submission_id,
|
|
270
|
+
'PageSize': 0
|
|
271
|
+
}), mock.call({
|
|
272
|
+
'WorkspaceID': self.workspace_id,
|
|
273
|
+
'Filter': {'IDs': ['fake_run_id']},
|
|
274
|
+
}), mock.call({
|
|
275
|
+
'WorkspaceID': self.workspace_id,
|
|
276
|
+
'SubmissionID': self.submission_id,
|
|
277
|
+
})
|
|
278
|
+
])
|
|
279
|
+
# wait for a while to make cache overdue
|
|
280
|
+
time.sleep(2)
|
|
281
|
+
with patch.object(BioOsService, "list_runs",
|
|
282
|
+
return_value=self.finished_list_runs_val) as list_runs:
|
|
283
|
+
with patch.object(BioOsService, "list_tasks",
|
|
284
|
+
return_value=self.finished_list_tasks_val) as list_tasks:
|
|
285
|
+
repr(run)
|
|
286
|
+
list_runs.assert_called_once()
|
|
287
|
+
list_tasks.assert_called_once()
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from unittest import mock
|
|
3
|
+
from unittest.mock import patch
|
|
4
|
+
|
|
5
|
+
import pandas.testing
|
|
6
|
+
from pandas import DataFrame
|
|
7
|
+
|
|
8
|
+
from bioos import bioos
|
|
9
|
+
from bioos.service.BioOsService import BioOsService
|
|
10
|
+
from bioos.tests.base import BaseInit
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class TestWorkspaces(BaseInit):
|
|
14
|
+
list_workspace_val = {
|
|
15
|
+
'Items':
|
|
16
|
+
[{'ID': BaseInit.workspace_id, 'Name': 'test-gqm',
|
|
17
|
+
'Description': 'test-gqm', 'CreateTime': 1661326698,
|
|
18
|
+
'UpdateTime': 1661326698, 'OwnerName': 'test',
|
|
19
|
+
'CoverDownloadURL':
|
|
20
|
+
'https://fake.tos-s3-cn-beijing.volces.com/template-cover/pic7.png?XXXXXXXXXXXX',
|
|
21
|
+
'Role': 'Admin', 'S3Bucket': 'bioos-dev-fake-workspace'}],
|
|
22
|
+
'PageNumber': 1, 'PageSize': 10, 'TotalCount': 1}
|
|
23
|
+
notebook_env_info = {
|
|
24
|
+
'Items':
|
|
25
|
+
[{'ClusterInfo':
|
|
26
|
+
{'ID': 'default',
|
|
27
|
+
'Name': 'Volcengine Container Cluster',
|
|
28
|
+
'Status': 'Running',
|
|
29
|
+
'StartTime': 1668596478,
|
|
30
|
+
'Description': 'Default Volcengine Container Cluster',
|
|
31
|
+
'Bound': True,
|
|
32
|
+
'Public': True,
|
|
33
|
+
'ExternalConfig': {
|
|
34
|
+
'WESEndpoint': 'http://localhost:8080/ga4gh/wes/v1',
|
|
35
|
+
'JupyterhubEndpoint': 'http://jupyterhub.fake.com/jupyterhub',
|
|
36
|
+
'JupyterhubJWTSecret': '',
|
|
37
|
+
'ResourceScheduler': 'Kubernetes',
|
|
38
|
+
'Filesystem': 'tos'}},
|
|
39
|
+
'Type': 'notebook', 'BindTime': 1676534060}], 'TotalCount': 1
|
|
40
|
+
}
|
|
41
|
+
workflow_env_info = {
|
|
42
|
+
'Items':
|
|
43
|
+
[{'ClusterInfo':
|
|
44
|
+
{'ID': 'default',
|
|
45
|
+
'Name': 'Volcengine Container Cluster',
|
|
46
|
+
'Status': 'Running',
|
|
47
|
+
'StartTime': 1668596478,
|
|
48
|
+
'Description': 'Default Volcengine Container Cluster',
|
|
49
|
+
'Bound': True,
|
|
50
|
+
'Public': True,
|
|
51
|
+
'ExternalConfig': {
|
|
52
|
+
'WESEndpoint': 'http://localhost:8080/ga4gh/wes/v1',
|
|
53
|
+
'JupyterhubEndpoint': 'http://jupyterhub.fake.com/jupyterhub',
|
|
54
|
+
'JupyterhubJWTSecret': '',
|
|
55
|
+
'ResourceScheduler': 'Kubernetes',
|
|
56
|
+
'Filesystem': 'tos'}},
|
|
57
|
+
'Type': 'workflow', 'BindTime': 1676534060}], 'TotalCount': 1
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
def list_cluster_side_effect(self, params):
|
|
61
|
+
if params.get("Type") == "notebook":
|
|
62
|
+
return self.notebook_env_info
|
|
63
|
+
else:
|
|
64
|
+
return self.workflow_env_info
|
|
65
|
+
|
|
66
|
+
def __init__(self, *args, **kwargs):
|
|
67
|
+
super(TestWorkspaces, self).__init__(*args, **kwargs)
|
|
68
|
+
self.ws = bioos.workspace(self.workspace_id)
|
|
69
|
+
|
|
70
|
+
def test_singleton(self):
|
|
71
|
+
ws = bioos.workspace(self.workspace_id)
|
|
72
|
+
self.assertEqual(self.ws, ws)
|
|
73
|
+
|
|
74
|
+
def test_repr_info_and_cache_call(self):
|
|
75
|
+
with patch.object(BioOsService, "list_workspaces",
|
|
76
|
+
return_value=self.list_workspace_val) as success_list_workspaces:
|
|
77
|
+
with patch.object(BioOsService, "list_cluster",
|
|
78
|
+
side_effect=self.list_cluster_side_effect) as success_list_cluster:
|
|
79
|
+
# makes no call
|
|
80
|
+
self.ws.data_models
|
|
81
|
+
# call get_workspace and list_cluster once
|
|
82
|
+
repr(self.ws)
|
|
83
|
+
basic_info = self.ws.basic_info
|
|
84
|
+
env_info = self.ws.env_info
|
|
85
|
+
self.assertEqual(basic_info["name"],
|
|
86
|
+
self.list_workspace_val.get("Items")[0].get('Name'))
|
|
87
|
+
self.assertEqual(basic_info["description"],
|
|
88
|
+
self.list_workspace_val.get("Items")[0].get('Description'))
|
|
89
|
+
self.assertEqual(basic_info["s3_bucket"],
|
|
90
|
+
self.list_workspace_val.get("Items")[0].get("S3Bucket"))
|
|
91
|
+
self.assertEqual(basic_info["owner"],
|
|
92
|
+
self.list_workspace_val.get("Items")[0].get("OwnerName"))
|
|
93
|
+
self.assertEqual(basic_info["create_time"],
|
|
94
|
+
datetime.fromtimestamp(
|
|
95
|
+
self.list_workspace_val.get("Items")[0].get("CreateTime"))
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
pandas.testing.assert_frame_equal(env_info, DataFrame.from_records([
|
|
99
|
+
{"cluster_id": "default", "name": "Volcengine Container Cluster",
|
|
100
|
+
"description": "Default Volcengine Container Cluster", "type": "notebook"},
|
|
101
|
+
{"cluster_id": "default", "name": "Volcengine Container Cluster",
|
|
102
|
+
"description": "Default Volcengine Container Cluster", "type": "workflow"},
|
|
103
|
+
]))
|
|
104
|
+
|
|
105
|
+
success_list_workspaces.assert_called_once_with({"Filter": {"IDs": [self.workspace_id]}})
|
|
106
|
+
success_list_cluster.assert_has_calls([
|
|
107
|
+
mock.call(params={
|
|
108
|
+
'Type': "notebook",
|
|
109
|
+
"ID": self.workspace_id}
|
|
110
|
+
),
|
|
111
|
+
mock.call(params={
|
|
112
|
+
'Type': "workflow",
|
|
113
|
+
"ID": self.workspace_id}
|
|
114
|
+
)
|
|
115
|
+
])
|
bioos/utils/__init__.py
ADDED
|
File without changes
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import threading
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
# helper_convert_pattern1 = re.compile(r'(.)([A-Z][a-z]+)')
|
|
6
|
+
# helper_convert_pattern2 = re.compile(r'([a-z0-9])([A-Z])')
|
|
7
|
+
#
|
|
8
|
+
#
|
|
9
|
+
# def camel_to_snake(case: str) -> str:
|
|
10
|
+
# return helper_convert_pattern2.sub(
|
|
11
|
+
# r'\1_\2',
|
|
12
|
+
# helper_convert_pattern1.sub(
|
|
13
|
+
# r'\1_\2',
|
|
14
|
+
# case
|
|
15
|
+
# )
|
|
16
|
+
# ).lower()
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def dict_str(dic: dict) -> str:
|
|
20
|
+
res_str = ""
|
|
21
|
+
for k, v in dic.items():
|
|
22
|
+
res_str += f"{k}: {v}\n"
|
|
23
|
+
return res_str
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def s3_endpoint_mapping(s3_endpoint: str) -> str:
|
|
27
|
+
return s3_endpoint.replace("tos-s3", "tos")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def is_json(myjson: str):
|
|
31
|
+
try:
|
|
32
|
+
json.loads(myjson)
|
|
33
|
+
except ValueError:
|
|
34
|
+
return False
|
|
35
|
+
return True
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def submission_name(workflow_name, submission_name_suffix):
|
|
39
|
+
return '{}-history-{}'.format(workflow_name, submission_name_suffix)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def instance_key(cls, *args, **kwargs):
|
|
43
|
+
return cls.__name__ + "%" + str(args) + "%" + str(kwargs)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class SingletonType(type):
|
|
47
|
+
_instance_lock = threading.RLock()
|
|
48
|
+
|
|
49
|
+
def __call__(cls, *args, **kwargs):
|
|
50
|
+
if not hasattr(cls, "_instance"):
|
|
51
|
+
cls._instance = {}
|
|
52
|
+
key = instance_key(cls, *args, **kwargs)
|
|
53
|
+
if key not in getattr(cls, "_instance").keys():
|
|
54
|
+
with SingletonType._instance_lock:
|
|
55
|
+
if key not in getattr(cls, "_instance").keys():
|
|
56
|
+
cls._instance[key] = super(SingletonType, cls).__call__(*args, **kwargs)
|
|
57
|
+
return cls._instance[key]
|
bioos/utils/workflows.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 GBA-BI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: pybioos
|
|
3
|
+
Version: 0.0.3
|
|
4
|
+
Summary: BioOs SDK for Python
|
|
5
|
+
Home-page: https://github.com/GBA-BI/pybioos
|
|
6
|
+
Author: Jilong Liu
|
|
7
|
+
Author-email: liu_jilong@gzlab.ac.cn
|
|
8
|
+
License: MIT Licence
|
|
9
|
+
Keywords: pip,bioos
|
|
10
|
+
Platform: any
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering :: Interface Engine/Protocol Translator
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Requires-Dist: volcengine >=1.0.61
|
|
17
|
+
Requires-Dist: tabulate >=0.8.10
|
|
18
|
+
Requires-Dist: click >=8.0.0
|
|
19
|
+
Requires-Dist: pandas >=1.3.0
|
|
20
|
+
Requires-Dist: tos ==2.3.4
|
|
21
|
+
Requires-Dist: cachetools >=5.2.0
|
|
22
|
+
Requires-Dist: typing-extensions >=4.4.0
|
|
23
|
+
Requires-Dist: apscheduler >=3.10.4
|
|
24
|
+
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
bioos/__about__.py,sha256=BHwVVBX9xSoN_4elSOrXO8yb5rdj4AGsueI3EY6_FcA,56
|
|
2
|
+
bioos/__init__.py,sha256=4GZKi13lDTD25YBkGakhZyEQZWTER_OWQMNPoH_UM2c,22
|
|
3
|
+
bioos/bioos.py,sha256=fHzOb1l5wYxw6NVYYZDiFcgk4V28BAgWEc3ev12reWs,2409
|
|
4
|
+
bioos/bioos_workflow.py,sha256=vdL8GVgYICetmqKkXIa3lu8hZRzWfdP_lzX_1HSHluE,9606
|
|
5
|
+
bioos/config.py,sha256=L0CVtN2hpW8b-0xkLpGkTKgZsCqEZkhYVAwbRQDs0MI,4231
|
|
6
|
+
bioos/errors.py,sha256=Lzz2rkjDOTR2X9CnVkmsmqeOgmNqbi46WAxnC6LEGm0,2459
|
|
7
|
+
bioos/log.py,sha256=twiCvf5IgJB7uvzANwBluSlztJN8ZrxbGZUBGlZ0vps,3204
|
|
8
|
+
bioos/internal/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
9
|
+
bioos/internal/tos.py,sha256=bIb-nDuW6SCw8sBUk9bdB9GXw0oQi5kU_ARC4VCuLHA,11985
|
|
10
|
+
bioos/models/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
11
|
+
bioos/models/models.py,sha256=HPCLZ4jK2HDth4vrlVHba21CiW6y7y5im1kOjV4adc8,391
|
|
12
|
+
bioos/resource/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
13
|
+
bioos/resource/data_models.py,sha256=enKp8yyQI8IbRqe--0Xtyg1XzOwQQPQzoQsx_hNuZ6E,5089
|
|
14
|
+
bioos/resource/files.py,sha256=TshetJeDU_pUQ-2jMbUnas6PARW_cCyjSP7mz0y0SPE,7847
|
|
15
|
+
bioos/resource/utility.py,sha256=emY7qVLLLvGmQYlVj-_bLAxU7i1GfQOUybdRkfEDwVA,1300
|
|
16
|
+
bioos/resource/workflows.py,sha256=06e9KS3Bm73mh9U6cDI7g8TmReM62EcgIjAxPGaqXaw,19541
|
|
17
|
+
bioos/resource/workspaces.py,sha256=Gmr8y_sjK7TQbhMhQ_7rxqR1KFcwU72I95YYCFrrLBQ,3995
|
|
18
|
+
bioos/service/BioOsService.py,sha256=HuYUEwomHCLpA1MYgVqGyWAQWHM-_BHB-jmy9VsOlnQ,6724
|
|
19
|
+
bioos/service/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
20
|
+
bioos/service/api.py,sha256=Khihn187bACEfBcJ-tRS9JO29-VCBsH0-9qq-i5WxkQ,8737
|
|
21
|
+
bioos/service/config.py,sha256=FbBsb6CpcLsQZH7n8uuUbFVhkpqYOEnOe0xGkA7ZrjA,1009
|
|
22
|
+
bioos/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
23
|
+
bioos/tests/base.py,sha256=B7jSiMTkSN0wv1oVqtwlW8QuKMbrmEIZgXH1jxx1EsU,606
|
|
24
|
+
bioos/tests/bioos.py,sha256=tq6S9OcVqwmQ2V9qa7swRL1-IytwYC5P4buW1Sy-5Q0,1836
|
|
25
|
+
bioos/tests/data_models.py,sha256=rcj1-XooBIjkGHd8zrzRC0IlL9IVBj_sis8lbqv7Xrg,13641
|
|
26
|
+
bioos/tests/files.py,sha256=YgT0N1VdvmFVldtdqepAUkJQvEeuw_g3Ft9wul1rs2c,6926
|
|
27
|
+
bioos/tests/utils.py,sha256=PZ4e1AtU4Mt5Z8eSC1vda26pPE2ODghhAmICOlkl550,1472
|
|
28
|
+
bioos/tests/workflows.py,sha256=N70oWeSb8-7UcDqVP7e6oJ2QyDG1beA6_GWQy7EOyNo,14557
|
|
29
|
+
bioos/tests/workspaces.py,sha256=LuuRrTs2XqfE5mGQyJNl9RBtuMb4NZHBJFoO8HMZVYQ,5229
|
|
30
|
+
bioos/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
31
|
+
bioos/utils/common_tools.py,sha256=a8xABCtmPS3DT7zh5bs_yRR-upDNmooO-ZpwVukJ0Rk,1488
|
|
32
|
+
bioos/utils/workflows.py,sha256=zRbwTUigoM5V5LFOgzQPm3kwxt5Ogz95OFfefJc6Fjo,133
|
|
33
|
+
pybioos-0.0.3.dist-info/LICENSE,sha256=cPkGXsgfPgEhIns7Lt3Avxx0Uy-VbdsoP8jvNGuj3cE,1063
|
|
34
|
+
pybioos-0.0.3.dist-info/METADATA,sha256=62FUtlPrricJ59qHOQ_r3UG5IqkJ3VCbbOH-pN1E_2Y,770
|
|
35
|
+
pybioos-0.0.3.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
36
|
+
pybioos-0.0.3.dist-info/entry_points.txt,sha256=8TRx1zyu7ja3x5RNaeFxeiYTj_-tiWydbuSulxi3TM0,59
|
|
37
|
+
pybioos-0.0.3.dist-info/top_level.txt,sha256=llpzydkKVDSaWZgz3bsTUsQmhoQpc_JcRJg2-H-5a2U,6
|
|
38
|
+
pybioos-0.0.3.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
bioos
|