pybiolib 1.1.1881__py3-none-any.whl → 1.1.2193__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.
Files changed (58) hide show
  1. biolib/__init__.py +11 -4
  2. biolib/_data_record/data_record.py +278 -0
  3. biolib/_internal/data_record/__init__.py +1 -1
  4. biolib/_internal/data_record/data_record.py +95 -151
  5. biolib/_internal/data_record/remote_storage_endpoint.py +18 -7
  6. biolib/_internal/file_utils.py +77 -0
  7. biolib/_internal/fuse_mount/__init__.py +1 -0
  8. biolib/_internal/fuse_mount/experiment_fuse_mount.py +209 -0
  9. biolib/_internal/http_client.py +29 -9
  10. biolib/_internal/lfs/__init__.py +1 -0
  11. biolib/_internal/libs/__init__.py +1 -0
  12. biolib/_internal/libs/fusepy/__init__.py +1257 -0
  13. biolib/_internal/push_application.py +1 -1
  14. biolib/_internal/runtime.py +2 -56
  15. biolib/_internal/types/__init__.py +4 -0
  16. biolib/_internal/types/app.py +9 -0
  17. biolib/_internal/types/data_record.py +40 -0
  18. biolib/_internal/types/experiment.py +10 -0
  19. biolib/_internal/types/resource.py +14 -0
  20. biolib/_internal/types/typing.py +7 -0
  21. biolib/_runtime/runtime.py +80 -0
  22. biolib/api/__init__.py +1 -0
  23. biolib/api/client.py +39 -17
  24. biolib/app/app.py +34 -71
  25. biolib/biolib_api_client/api_client.py +9 -2
  26. biolib/biolib_api_client/app_types.py +2 -2
  27. biolib/biolib_api_client/biolib_job_api.py +6 -0
  28. biolib/biolib_api_client/job_types.py +4 -4
  29. biolib/biolib_api_client/lfs_types.py +8 -2
  30. biolib/biolib_binary_format/remote_endpoints.py +12 -10
  31. biolib/biolib_binary_format/utils.py +23 -3
  32. biolib/cli/auth.py +1 -1
  33. biolib/cli/data_record.py +43 -6
  34. biolib/cli/lfs.py +10 -6
  35. biolib/compute_node/cloud_utils/cloud_utils.py +13 -16
  36. biolib/compute_node/job_worker/executors/docker_executor.py +126 -108
  37. biolib/compute_node/job_worker/job_storage.py +3 -4
  38. biolib/compute_node/job_worker/job_worker.py +25 -15
  39. biolib/compute_node/remote_host_proxy.py +61 -84
  40. biolib/compute_node/webserver/webserver_types.py +0 -1
  41. biolib/experiments/experiment.py +75 -44
  42. biolib/jobs/job.py +98 -19
  43. biolib/jobs/job_result.py +46 -21
  44. biolib/jobs/types.py +1 -1
  45. biolib/runtime/__init__.py +2 -1
  46. biolib/sdk/__init__.py +18 -7
  47. biolib/typing_utils.py +2 -7
  48. biolib/user/sign_in.py +2 -2
  49. biolib/utils/seq_util.py +38 -35
  50. {pybiolib-1.1.1881.dist-info → pybiolib-1.1.2193.dist-info}/METADATA +1 -1
  51. {pybiolib-1.1.1881.dist-info → pybiolib-1.1.2193.dist-info}/RECORD +55 -44
  52. biolib/experiments/types.py +0 -9
  53. biolib/lfs/__init__.py +0 -4
  54. biolib/lfs/utils.py +0 -153
  55. /biolib/{lfs → _internal/lfs}/cache.py +0 -0
  56. {pybiolib-1.1.1881.dist-info → pybiolib-1.1.2193.dist-info}/LICENSE +0 -0
  57. {pybiolib-1.1.1881.dist-info → pybiolib-1.1.2193.dist-info}/WHEEL +0 -0
  58. {pybiolib-1.1.1881.dist-info → pybiolib-1.1.2193.dist-info}/entry_points.txt +0 -0
@@ -1,13 +1,19 @@
1
1
  from biolib.typing_utils import TypedDict
2
2
 
3
3
 
4
- class LargeFileSystemVersion(TypedDict):
4
+ class DataRecordVersion(TypedDict):
5
5
  presigned_download_url: str
6
6
  size_bytes: int
7
7
  uri: str
8
8
  uuid: str
9
9
 
10
10
 
11
- class LargeFileSystem(TypedDict):
11
+ class DataRecordInfo(TypedDict):
12
12
  uri: str
13
13
  uuid: str
14
+
15
+
16
+ class DataRecordVersionInfo(TypedDict):
17
+ resource_uri: str
18
+ resource_uuid: str
19
+ resource_version_uuid: str
@@ -1,25 +1,27 @@
1
1
  from datetime import datetime, timedelta
2
- # from urllib.parse import urlparse, parse_qs
3
-
4
- from biolib.biolib_logging import logger
5
2
 
6
3
  from biolib.biolib_api_client.biolib_job_api import BiolibJobApi
7
4
  from biolib.biolib_binary_format.utils import RemoteEndpoint
8
5
 
6
+ # from urllib.parse import urlparse, parse_qs
7
+ from biolib.biolib_logging import logger
8
+ from biolib.typing_utils import Literal
9
+
9
10
 
10
- class RemoteJobStorageResultEndpoint(RemoteEndpoint):
11
- def __init__(self, job_id: str, job_auth_token: str):
12
- self._job_id = job_id
13
- self._job_auth_token = job_auth_token
11
+ class RemoteJobStorageEndpoint(RemoteEndpoint):
12
+ def __init__(self, job_uuid: str, job_auth_token: str, storage_type: Literal['input', 'output']):
14
13
  self._expires_at = None
14
+ self._job_auth_token = job_auth_token
15
+ self._job_uuid = job_uuid
15
16
  self._presigned_url = None
17
+ self._storage_type: Literal['input', 'output'] = storage_type
16
18
 
17
19
  def get_remote_url(self):
18
20
  if not self._presigned_url or datetime.utcnow() > self._expires_at:
19
21
  self._presigned_url = BiolibJobApi.get_job_storage_download_url(
20
22
  job_auth_token=self._job_auth_token,
21
- job_uuid=self._job_id,
22
- storage_type='results'
23
+ job_uuid=self._job_uuid,
24
+ storage_type='results' if self._storage_type == 'output' else 'input',
23
25
  )
24
26
  self._expires_at = datetime.utcnow() + timedelta(minutes=8)
25
27
  # TODO: Use expires at from url
@@ -27,6 +29,6 @@ class RemoteJobStorageResultEndpoint(RemoteEndpoint):
27
29
  # query_params = parse_qs(parsed_url.query)
28
30
  # time_at_generation = datetime.datetime.strptime(query_params['X-Amz-Date'][0], '%Y%m%dT%H%M%SZ')
29
31
  # self._expires_at = time_at_generation + timedelta(seconds=int(query_params['X-Amz-Expires'][0]))
30
- logger.debug(f'Job "{self._job_id}" fetched presigned URL with expiry at {self._expires_at.isoformat()}')
32
+ logger.debug(f'Job "{self._job_uuid}" fetched presigned URL with expiry at {self._expires_at.isoformat()}')
31
33
 
32
34
  return self._presigned_url
@@ -1,7 +1,8 @@
1
1
  from abc import ABC, abstractmethod
2
2
  import io
3
+ import math
3
4
  from typing import Optional, Callable
4
-
5
+ from biolib.typing_utils import Iterator
5
6
  from biolib._internal.http_client import HttpClient
6
7
 
7
8
 
@@ -147,5 +148,24 @@ class LazyLoadedFile:
147
148
  def get_file_handle(self) -> io.BufferedIOBase:
148
149
  return io.BytesIO(self.get_data())
149
150
 
150
- def get_data(self) -> bytes:
151
- return self._buffer.get_data(start=self.start, length=self._length)
151
+ def get_data(self, start=0, length=None) -> bytes:
152
+ start_offset = start + self.start
153
+ # make sure length doesn't go outside file boundaries
154
+ length_to_end_of_file = max(self._length - start, 0)
155
+ if length is None:
156
+ length_to_request = length_to_end_of_file
157
+ else:
158
+ length_to_request = min(length, length_to_end_of_file)
159
+ return self._buffer.get_data(start=start_offset, length=length_to_request)
160
+
161
+ def get_data_iterator(self) -> Iterator[bytes]:
162
+ if self._length == 0:
163
+ yield b''
164
+ else:
165
+ chunk_size = 10_000_000
166
+ chunks_to_yield = math.ceil(self._length / chunk_size)
167
+ for chunk_idx in range(chunks_to_yield - 1):
168
+ yield self._buffer.get_data(start=self.start+chunk_idx*chunk_size, length=chunk_size)
169
+ data_already_yielded = (chunks_to_yield - 1)*chunk_size
170
+ yield self._buffer.get_data(start=self.start+data_already_yielded,
171
+ length=self._length - data_already_yielded)
biolib/cli/auth.py CHANGED
@@ -52,7 +52,7 @@ def whoami() -> None:
52
52
  email = user_dict['email']
53
53
  intrinsic_account = [account for account in user_dict['accounts'] if account['role'] == 'intrinsic'][0]
54
54
  display_name = intrinsic_account['display_name']
55
- print(f'Name: {display_name}\nEmail: {email}')
55
+ print(f'Name: {display_name}\nEmail: {email}\nLogged into: {client.base_url}')
56
56
  else:
57
57
  print('Not logged in', file=sys.stderr)
58
58
  exit(1)
biolib/cli/data_record.py CHANGED
@@ -1,9 +1,11 @@
1
+ import json
1
2
  import logging
2
3
  import os
4
+ from typing import Dict, List
3
5
 
4
6
  import click
5
7
 
6
- from biolib._internal.data_record import DataRecord
8
+ from biolib._data_record.data_record import DataRecord
7
9
  from biolib.biolib_logging import logger, logger_no_user_data
8
10
  from biolib.typing_utils import Optional
9
11
 
@@ -15,11 +17,19 @@ def data_record() -> None:
15
17
 
16
18
 
17
19
  @data_record.command(help='Create a Data Record')
18
- @click.option('--destination', type=str, required=True)
20
+ @click.argument('uri', required=True)
21
+ @click.option('--data-path', required=True, type=click.Path(exists=True))
22
+ @click.option('--record-type', required=False, type=str, default=None)
23
+ def create(uri: str, data_path: str, record_type: Optional[str]) -> None:
24
+ DataRecord.create(destination=uri, data_path=data_path, record_type=record_type)
25
+
26
+
27
+ @data_record.command(help='Update a Data Record')
28
+ @click.argument('uri', required=True)
19
29
  @click.option('--data-path', required=True, type=click.Path(exists=True))
20
- @click.option('--name', type=str, required=False)
21
- def create(destination: str, data_path: str, name: Optional[str] = None) -> None:
22
- DataRecord.create(destination, data_path, name)
30
+ @click.option('--chunk-size', default=None, required=False, type=click.INT, help='The size of each chunk (In MB)')
31
+ def update(uri: str, data_path: str, chunk_size: Optional[int]) -> None:
32
+ DataRecord.get_by_uri(uri=uri).update(data_path=data_path, chunk_size_in_mb=chunk_size)
23
33
 
24
34
 
25
35
  @data_record.command(help='Download files from a Data Record')
@@ -27,7 +37,7 @@ def create(destination: str, data_path: str, name: Optional[str] = None) -> None
27
37
  @click.option('--file', required=False, type=str)
28
38
  @click.option('--path-filter', required=False, type=str, hide_input=True)
29
39
  def download(uri: str, file: Optional[str], path_filter: Optional[str]) -> None:
30
- record = DataRecord(uri=uri)
40
+ record = DataRecord.get_by_uri(uri=uri)
31
41
  if file is not None:
32
42
  try:
33
43
  file_obj = [file_obj for file_obj in record.list_files() if file_obj.path == file][0]
@@ -41,3 +51,30 @@ def download(uri: str, file: Optional[str], path_filter: Optional[str]) -> None:
41
51
  else:
42
52
  assert not os.path.exists(record.name), f'Directory with name {record.name} already exists in current directory'
43
53
  record.save_files(output_dir=record.name, path_filter=path_filter)
54
+
55
+
56
+ @data_record.command(help='Describe a Data Record')
57
+ @click.argument('uri', required=True)
58
+ @click.option('--json', 'output_as_json', is_flag=True, default=False, required=False, help='Format output as JSON')
59
+ def describe(uri: str, output_as_json: bool) -> None:
60
+ record = DataRecord.get_by_uri(uri)
61
+ files_info: List[Dict] = []
62
+ total_size_in_bytes = 0
63
+ for file in record.list_files():
64
+ files_info.append({'path': file.path, 'size_bytes': file.length})
65
+ total_size_in_bytes += file.length
66
+
67
+ if output_as_json:
68
+ print(
69
+ json.dumps(
70
+ obj={'uri': record.uri, 'size_bytes': total_size_in_bytes, 'files': files_info},
71
+ indent=4,
72
+ )
73
+ )
74
+ else:
75
+ print(f'Data Record {record.uri}\ntotal {total_size_in_bytes} bytes\n')
76
+ print('size bytes path')
77
+ for file_info in files_info:
78
+ size_string = str(file_info['size_bytes'])
79
+ leading_space_string = ' ' * (10 - len(size_string))
80
+ print(f"{leading_space_string}{size_string} {file_info['path']}")
biolib/cli/lfs.py CHANGED
@@ -7,9 +7,9 @@ from typing import Dict, List
7
7
  import click
8
8
 
9
9
  from biolib import biolib_errors
10
- from biolib._internal.data_record import DataRecord
10
+ from biolib._data_record.data_record import DataRecord
11
+ from biolib._internal.lfs import prune_lfs_cache
11
12
  from biolib.biolib_logging import logger, logger_no_user_data
12
- from biolib.lfs import create_large_file_system, prune_lfs_cache, push_large_file_system
13
13
  from biolib.typing_utils import Optional
14
14
 
15
15
 
@@ -21,9 +21,10 @@ def lfs() -> None:
21
21
  @lfs.command(help='Create a Large File System')
22
22
  @click.argument('uri', required=True)
23
23
  def create(uri: str) -> None:
24
+ logger.warning('This is command deprecated, please use "biolib data-record create" instead.')
24
25
  logger.configure(default_log_level=logging.INFO)
25
26
  logger_no_user_data.configure(default_log_level=logging.INFO)
26
- create_large_file_system(lfs_uri=uri)
27
+ DataRecord.create(destination=uri)
27
28
 
28
29
 
29
30
  @lfs.command(help='Push a new version of a Large File System')
@@ -31,10 +32,11 @@ def create(uri: str) -> None:
31
32
  @click.option('--path', required=True, type=click.Path(exists=True))
32
33
  @click.option('--chunk-size', default=None, required=False, type=click.INT, help='The size of each chunk (In MB)')
33
34
  def push(uri: str, path: str, chunk_size: Optional[int]) -> None:
35
+ logger.warning('This is command deprecated, please use "biolib data-record update" instead.')
34
36
  logger.configure(default_log_level=logging.INFO)
35
37
  logger_no_user_data.configure(default_log_level=logging.INFO)
36
38
  try:
37
- push_large_file_system(lfs_uri=uri, input_dir=path, chunk_size_in_mb=chunk_size)
39
+ DataRecord.get_by_uri(uri=uri).update(data_path=path, chunk_size_in_mb=chunk_size)
38
40
  except biolib_errors.BioLibError as error:
39
41
  print(f'An error occurred:\n{error.message}', file=sys.stderr)
40
42
  exit(1)
@@ -44,10 +46,11 @@ def push(uri: str, path: str, chunk_size: Optional[int]) -> None:
44
46
  @click.argument('uri', required=True)
45
47
  @click.option('--file-path', required=True, type=str)
46
48
  def download_file(uri: str, file_path: str) -> None:
49
+ logger.warning('This is command deprecated, please use "biolib data-record download" instead.')
47
50
  logger.configure(default_log_level=logging.INFO)
48
51
  logger_no_user_data.configure(default_log_level=logging.INFO)
49
52
  try:
50
- record = DataRecord(uri=uri)
53
+ record = DataRecord.get_by_uri(uri=uri)
51
54
  try:
52
55
  file_obj = [file_obj for file_obj in record.list_files() if file_obj.path == file_path][0]
53
56
  except IndexError:
@@ -66,7 +69,8 @@ def download_file(uri: str, file_path: str) -> None:
66
69
  @click.argument('uri', required=True)
67
70
  @click.option('--json', 'output_as_json', is_flag=True, default=False, required=False, help='Format output as JSON')
68
71
  def describe(uri: str, output_as_json: bool) -> None:
69
- data_record = DataRecord(uri)
72
+ logger.warning('This is command deprecated, please use "biolib data-record describe" instead.')
73
+ data_record = DataRecord.get_by_uri(uri)
70
74
  files_info: List[Dict] = []
71
75
  total_size_in_bytes = 0
72
76
  for file in data_record.list_files():
@@ -7,11 +7,11 @@ import time
7
7
  from datetime import datetime
8
8
  from socket import gethostbyname, gethostname
9
9
 
10
- from biolib import utils, api
11
- from biolib.biolib_logging import logger_no_user_data
12
- from biolib.typing_utils import Optional, List, Dict, cast
10
+ from biolib import api, utils
13
11
  from biolib.biolib_api_client import BiolibApiClient
14
- from biolib.compute_node.webserver.webserver_types import WebserverConfig, ComputeNodeInfo, ShutdownTimes
12
+ from biolib.biolib_logging import logger_no_user_data
13
+ from biolib.compute_node.webserver.webserver_types import ComputeNodeInfo, ShutdownTimes, WebserverConfig
14
+ from biolib.typing_utils import Dict, List, Optional, cast
15
15
 
16
16
 
17
17
  def trust_ceritificates(certs_data: List[str]) -> None:
@@ -54,15 +54,12 @@ class CloudUtils:
54
54
  pybiolib_version=utils.BIOLIB_PACKAGE_VERSION,
55
55
  ),
56
56
  base_url=CloudUtils._get_environment_variable_or_fail('BIOLIB_BASE_URL'),
57
- s3_general_storage_bucket_name=CloudUtils._get_environment_variable_or_fail(
58
- 'BIOLIB_S3_GENERAL_STORAGE_BUCKET_NAME',
59
- ),
60
57
  is_dev=os.environ.get('BIOLIB_DEV') == 'TRUE',
61
58
  shutdown_times=ShutdownTimes(
62
59
  auto_shutdown_time_in_seconds=CloudUtils._get_environment_variable_as_int(
63
60
  'BIOLIB_CLOUD_AUTO_SHUTDOWN_TIME_IN_SECONDS'
64
61
  ),
65
- )
62
+ ),
66
63
  )
67
64
 
68
65
  return CloudUtils._webserver_config
@@ -84,7 +81,7 @@ class CloudUtils:
84
81
  except BaseException as error_object:
85
82
  logger_no_user_data.error(f'Failed to deregister got error: {error_object}')
86
83
  else:
87
- logger_no_user_data.error("Not deregistering as environment is not cloud")
84
+ logger_no_user_data.error('Not deregistering as environment is not cloud')
88
85
 
89
86
  @staticmethod
90
87
  def shutdown() -> None:
@@ -98,7 +95,7 @@ class CloudUtils:
98
95
  except Exception as error: # pylint: disable=broad-except
99
96
  logger_no_user_data.error(f'Failed to shutdown got error: {error}')
100
97
  else:
101
- logger_no_user_data.error("Not running shutdown as environment is not cloud")
98
+ logger_no_user_data.error('Not running shutdown as environment is not cloud')
102
99
 
103
100
  @staticmethod
104
101
  def deregister_and_shutdown() -> None:
@@ -131,7 +128,7 @@ class CloudUtils:
131
128
  'auth_token': config['compute_node_info']['auth_token'],
132
129
  'cloud_job_id': cloud_job_id,
133
130
  'system_exception_code': system_exception_code,
134
- 'exit_code': exit_code
131
+ 'exit_code': exit_code,
135
132
  },
136
133
  )
137
134
  except BaseException as error:
@@ -152,14 +149,14 @@ class CloudUtils:
152
149
  data=cast(Dict[str, str], compute_node_info),
153
150
  )
154
151
  if response.status_code != 201:
155
- raise Exception("Non 201 error code")
152
+ raise Exception('Non 201 error code')
156
153
  else:
157
- logger_no_user_data.info("Compute node registered!")
154
+ logger_no_user_data.info('Compute node registered!')
158
155
  response_data = response.json()
159
- logger_no_user_data.info(f"Got data on register: {json.dumps(response_data)}")
156
+ logger_no_user_data.info(f'Got data on register: {json.dumps(response_data)}')
160
157
  certs = []
161
- for federation in response_data["federation"]:
162
- for cert_b64 in federation["certs_b64"]:
158
+ for federation in response_data['federation']:
159
+ for cert_b64 in federation['certs_b64']:
163
160
  certs.append(base64.b64decode(cert_b64).decode())
164
161
  trust_ceritificates(certs)
165
162