pybiolib 1.1.2123__py3-none-any.whl → 1.1.2135__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.
biolib/__init__.py CHANGED
@@ -12,7 +12,7 @@ from biolib.experiments.experiment import Experiment
12
12
  from biolib.biolib_api_client import BiolibApiClient as _BioLibApiClient, App
13
13
  from biolib.jobs import Job as _Job
14
14
  from biolib import user as _user
15
- from biolib.typing_utils import List, Optional
15
+ from biolib.typing_utils import List, Optional, cast as _cast
16
16
  from biolib._data_record.data_record import DataRecord as _DataRecord
17
17
 
18
18
  import biolib.api
@@ -57,8 +57,11 @@ def fetch_data_records(uri: Optional[str] = None, count: Optional[int] = None) -
57
57
  return _DataRecord.fetch(uri, count)
58
58
 
59
59
 
60
- def get_experiment(name: str) -> Experiment:
61
- return Experiment(name)
60
+ def get_experiment(uri: Optional[str] = None, name: Optional[str] = None) -> Experiment:
61
+ if (not uri and not name) or (uri and name):
62
+ raise ValueError('Must provide either uri or name')
63
+
64
+ return Experiment.get_by_uri(uri=_cast(str, uri or name))
62
65
 
63
66
 
64
67
  def show_jobs(count: int = 25) -> None:
@@ -1 +1,2 @@
1
- from .resources import * # noqa: F403
1
+ from .data_record import * # noqa: F403
2
+ from .resource import * # noqa: F403
@@ -0,0 +1,12 @@
1
+ from .typing import Dict, List, TypedDict
2
+
3
+
4
+ class DataRecordValidationRuleDict(TypedDict):
5
+ path: str
6
+ type: str
7
+ rule: Dict
8
+
9
+
10
+ class DataRecordTypeDict(TypedDict):
11
+ name: str
12
+ validation_rules: List[Dict]
@@ -3,9 +3,7 @@ from collections import OrderedDict
3
3
 
4
4
  import biolib._internal.types as _types
5
5
  from biolib import api
6
- from biolib._internal.http_client import HttpError
7
- from biolib.biolib_errors import BioLibError, NotFound
8
- from biolib.experiments.types import ExperimentDict
6
+ from biolib.biolib_errors import BioLibError
9
7
  from biolib.jobs.job import Job
10
8
  from biolib.jobs.types import JobsPaginatedResponse
11
9
  from biolib.tables import BioLibTable
@@ -24,11 +22,8 @@ class Experiment:
24
22
  }
25
23
  )
26
24
 
27
- def __init__(self, uri: str, _experiment_dict: Optional[ExperimentDict] = None):
28
- if not _experiment_dict:
29
- self._experiment_dict: ExperimentDict = self._get_or_create_by_uri(uri)
30
- else:
31
- self._experiment_dict = _experiment_dict
25
+ def __init__(self, uri: str, _resource_dict: Optional[_types.ResourceDict] = None):
26
+ self._resource_dict: _types.ResourceDict = _resource_dict or self._get_or_create_resource_dict(uri)
32
27
 
33
28
  def __enter__(self):
34
29
  Experiment._BIOLIB_EXPERIMENTS.append(self)
@@ -37,18 +32,29 @@ class Experiment:
37
32
  Experiment._BIOLIB_EXPERIMENTS.pop()
38
33
 
39
34
  def __str__(self):
40
- return f'Experiment: {self.name}'
35
+ return f'Experiment: {self.uri}'
41
36
 
42
37
  def __repr__(self):
43
- return f'Experiment: {self.name}'
38
+ return f'Experiment: {self.uri}'
44
39
 
45
40
  @property
46
41
  def uuid(self) -> str:
47
- return self._experiment_dict['uuid']
42
+ return self._resource_dict['uuid']
48
43
 
49
44
  @property
50
45
  def name(self) -> str:
51
- return self._experiment_dict['name']
46
+ return self._resource_dict['name']
47
+
48
+ @property
49
+ def uri(self) -> str:
50
+ return self._resource_dict['uri']
51
+
52
+ @property
53
+ def _experiment_dict(self) -> _types.ExperimentDict:
54
+ if not self._resource_dict['experiment']:
55
+ raise ValueError(f'Resource {self.uri} is not an Experiment')
56
+
57
+ return self._resource_dict['experiment']
52
58
 
53
59
  @staticmethod
54
60
  def get_experiment_in_context() -> Optional['Experiment']:
@@ -68,25 +74,19 @@ class Experiment:
68
74
 
69
75
  @staticmethod
70
76
  def get_by_uri(uri: str) -> 'Experiment':
71
- resource_dict: _types.ResourceDict = api.client.get('/resources/', params={'uri': uri}).json()
77
+ query_param_key = 'uri' if '/' in uri else 'name'
78
+ resource_dict: _types.ResourceDict = api.client.get('/resource/', params={query_param_key: uri}).json()
72
79
  if not resource_dict['experiment']:
73
- raise ValueError('Resource from URI is not an experiment')
80
+ raise ValueError(f'Resource {uri} is not an experiment')
74
81
 
75
- legacy_experiment_dict = ExperimentDict(
76
- created_at=resource_dict['created_at'],
77
- job_count=resource_dict['experiment']['job_count'],
78
- job_running_count=resource_dict['experiment']['job_running_count'],
79
- name=resource_dict['name'],
80
- uuid=resource_dict['uuid'],
81
- )
82
- return Experiment(uri=resource_dict['uri'], _experiment_dict=legacy_experiment_dict)
82
+ return Experiment(uri=resource_dict['uri'], _resource_dict=resource_dict)
83
83
 
84
84
  def wait(self) -> None:
85
- self._refetch_experiment_dict()
85
+ self._refetch()
86
86
  while self._experiment_dict['job_running_count'] > 0:
87
87
  print(f"Waiting for {self._experiment_dict['job_running_count']} jobs to finish", end='\r')
88
88
  time.sleep(5)
89
- self._refetch_experiment_dict()
89
+ self._refetch()
90
90
 
91
91
  print(f'All jobs of experiment {self.name} have finished')
92
92
 
@@ -171,34 +171,22 @@ class Experiment:
171
171
 
172
172
  return jobs
173
173
 
174
- def rename(self, name: Optional[str] = None, destination: Optional[str] = None) -> None:
175
- if destination:
176
- try:
177
- account_id = api.client.get(path=f'/account/{destination}/').json()['uuid']
178
- except HttpError as error:
179
- if error.code == 404:
180
- raise NotFound(f'Destination "{destination}" not found.') from None
181
- else:
182
- raise error
183
-
184
- api.client.patch(
185
- path=f'/apps/{self.uuid}/',
186
- data={'account_id': account_id},
187
- params={'resource_type': 'experiment'},
188
- )
174
+ def rename(self, destination: str) -> None:
175
+ api.client.patch(f'/resources/{self.uuid}/', data={'uri': destination})
176
+ self._refetch()
189
177
 
190
- if name:
191
- api.client.patch(path=f'/apps/{self.uuid}/', data={'name': name}, params={'resource_type': 'experiment'})
178
+ @staticmethod
179
+ def _get_resource_dict_by_uuid(uuid: str) -> _types.ResourceDict:
180
+ resource_dict: _types.ResourceDict = api.client.get(f'/resources/{uuid}/').json()
181
+ if not resource_dict['experiment']:
182
+ raise ValueError('Resource from URI is not an experiment')
192
183
 
193
- self._refetch_experiment_dict()
184
+ return resource_dict
194
185
 
195
186
  @staticmethod
196
- def _get_or_create_by_uri(uri: str) -> ExperimentDict:
197
- experiment_dict: ExperimentDict = api.client.post(
198
- path='/experiments/',
199
- data={'uri' if '/' in uri else 'name': uri},
200
- ).json()
201
- return experiment_dict
187
+ def _get_or_create_resource_dict(uri: str) -> _types.ResourceDict:
188
+ response_dict = api.client.post(path='/experiments/', data={'uri' if '/' in uri else 'name': uri}).json()
189
+ return Experiment._get_resource_dict_by_uuid(uuid=response_dict['uuid'])
202
190
 
203
- def _refetch_experiment_dict(self) -> None:
204
- self._experiment_dict = api.client.get(path=f'/experiments/{self.uuid}/').json()
191
+ def _refetch(self) -> None:
192
+ self._resource_dict = self._get_resource_dict_by_uuid(uuid=self._resource_dict['uuid'])
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pybiolib
3
- Version: 1.1.2123
3
+ Version: 1.1.2135
4
4
  Summary: BioLib Python Client
5
5
  Home-page: https://github.com/biolib
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  LICENSE,sha256=F2h7gf8i0agDIeWoBPXDMYScvQOz02pAWkKhTGOHaaw,1067
2
2
  README.md,sha256=_IH7pxFiqy2bIAmaVeA-iVTyUwWRjMIlfgtUbYTtmls,368
3
- biolib/__init__.py,sha256=yX8w8bDiY7CIxfKHFRF0U1hhwgCCIXtVr18Td5iNLp8,4135
3
+ biolib/__init__.py,sha256=_tThyzISH81yS9KXP_X3qEiKXmsIp5XOBcJIODfLVnc,4338
4
4
  biolib/_data_record/data_record.py,sha256=jUeCQjnVQLNLmlXO3rREEUnjXjOYuaQjBO7R66P6wFU,8909
5
5
  biolib/_internal/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  biolib/_internal/data_record/__init__.py,sha256=0T0CV6PfKc8itjMu-48sCJjcZQEzXl1ZLBqG_LjJTqQ,82
@@ -16,8 +16,9 @@ biolib/_internal/libs/__init__.py,sha256=Jdf4tNPqe_oIIf6zYml6TiqhL_02Vyqwge6IELr
16
16
  biolib/_internal/libs/fusepy/__init__.py,sha256=AWDzNFS-XV_5yKb0Qx7kggIhPzq1nj_BZS5y2Nso08k,41944
17
17
  biolib/_internal/push_application.py,sha256=8P7eXvySn7CRp5XBDkO3xjTGixS8g7-jD-_iwzM_XDI,10020
18
18
  biolib/_internal/runtime.py,sha256=9pZ3s3L7LGxdqOgnHh1KK3Jjyn_9MjhQmKHI-6hMT3U,448
19
- biolib/_internal/types/__init__.py,sha256=h2I2aupN01HbhBelL-qQa8FLuXiH1tB3kKl8dPdhmnc,39
20
- biolib/_internal/types/resources.py,sha256=LlxuiesDDv3TvfEmz_BCCxH0V650bNHtS_LpBMA25T4,256
19
+ biolib/_internal/types/__init__.py,sha256=yVxn48Z7N240X5yVYM-gsbqXDyLF9VJ6-mbNpFvVzgU,79
20
+ biolib/_internal/types/data_record.py,sha256=fPtWmrgL29zKGrzifr-4JOcpVp_4vVY0lNg8v6H_Bc8,220
21
+ biolib/_internal/types/resource.py,sha256=LlxuiesDDv3TvfEmz_BCCxH0V650bNHtS_LpBMA25T4,256
21
22
  biolib/_internal/types/typing.py,sha256=D4EKKEe7kDx0K6lJi-H_XLtk-8w6nu2fdqn9bvzI-Xo,288
22
23
  biolib/_internal/utils/__init__.py,sha256=p5vsIFyu-zYqBgdSMfwW9NC_jk7rXvvCbV4Bzd3As7c,630
23
24
  biolib/_runtime/runtime.py,sha256=zy9HrE4X5hBqm8doUHkckyflquSBDSXV3REhT2MQGas,2767
@@ -94,8 +95,7 @@ biolib/compute_node/webserver/webserver_types.py,sha256=2t8EaFKESnves3BA_NBdnS2y
94
95
  biolib/compute_node/webserver/webserver_utils.py,sha256=XWvwYPbWNR3qS0FYbLLp-MDDfVk0QdaAmg3xPrT0H2s,4234
95
96
  biolib/compute_node/webserver/worker_thread.py,sha256=26tG73TADnOcXsAr7Iyf6smrLlCqB4x-vvmpUb8WqnA,11569
96
97
  biolib/experiments/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
97
- biolib/experiments/experiment.py,sha256=o2gXMJVwK2SFljZ9RdTYFRH3jGKJmg3P39oERhEnZMQ,8126
98
- biolib/experiments/types.py,sha256=n9GxdFA7cLMfHvLLqLmZzX31ELeSSkMXFoEEdFsdWGY,171
98
+ biolib/experiments/experiment.py,sha256=4VkeRMxDnROQ0CE_su299FjzODEHwpvlLH-h4-TFPNQ,7610
99
99
  biolib/jobs/__init__.py,sha256=aIb2H2DHjQbM2Bs-dysFijhwFcL58Blp0Co0gimED3w,32
100
100
  biolib/jobs/job.py,sha256=OfG8cLd3AjGjiMWRlJRZdVVbLsRWSX-OM5nxJhR6mPQ,19136
101
101
  biolib/jobs/job_result.py,sha256=rALHiKYNaC9lHi_JJqBob1RubzNLwG9Z386kwRJjd2M,5885
@@ -114,8 +114,8 @@ biolib/utils/cache_state.py,sha256=u256F37QSRIVwqKlbnCyzAX4EMI-kl6Dwu6qwj-Qmag,3
114
114
  biolib/utils/multipart_uploader.py,sha256=XvGP1I8tQuKhAH-QugPRoEsCi9qvbRk-DVBs5PNwwJo,8452
115
115
  biolib/utils/seq_util.py,sha256=jC5WhH63FTD7SLFJbxQGA2hOt9NTwq9zHl_BEec1Z0c,4907
116
116
  biolib/utils/zip/remote_zip.py,sha256=0wErYlxir5921agfFeV1xVjf29l9VNgGQvNlWOlj2Yc,23232
117
- pybiolib-1.1.2123.dist-info/LICENSE,sha256=F2h7gf8i0agDIeWoBPXDMYScvQOz02pAWkKhTGOHaaw,1067
118
- pybiolib-1.1.2123.dist-info/METADATA,sha256=aKfd3kBoe55TCBeMBPtX0GTAfUOVHfw_jXauy_dSlkI,1508
119
- pybiolib-1.1.2123.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
120
- pybiolib-1.1.2123.dist-info/entry_points.txt,sha256=p6DyaP_2kctxegTX23WBznnrDi4mz6gx04O5uKtRDXg,42
121
- pybiolib-1.1.2123.dist-info/RECORD,,
117
+ pybiolib-1.1.2135.dist-info/LICENSE,sha256=F2h7gf8i0agDIeWoBPXDMYScvQOz02pAWkKhTGOHaaw,1067
118
+ pybiolib-1.1.2135.dist-info/METADATA,sha256=FdkUDiSOcWBss6_5vClW1valODFetu3Soa8jNm29IE4,1508
119
+ pybiolib-1.1.2135.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
120
+ pybiolib-1.1.2135.dist-info/entry_points.txt,sha256=p6DyaP_2kctxegTX23WBznnrDi4mz6gx04O5uKtRDXg,42
121
+ pybiolib-1.1.2135.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- from biolib.typing_utils import TypedDict
2
-
3
-
4
- class ExperimentDict(TypedDict):
5
- created_at: str
6
- job_count: int
7
- job_running_count: int
8
- name: str
9
- uuid: str
File without changes