pybiolib 1.2.911__py3-none-any.whl → 1.2.1642__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 pybiolib might be problematic. Click here for more details.
- biolib/__init__.py +33 -10
- biolib/_data_record/data_record.py +24 -11
- biolib/_index/index.py +51 -0
- biolib/_index/types.py +7 -0
- biolib/_internal/add_copilot_prompts.py +3 -5
- biolib/_internal/add_gui_files.py +59 -0
- biolib/_internal/data_record/data_record.py +1 -1
- biolib/_internal/data_record/push_data.py +1 -1
- biolib/_internal/data_record/remote_storage_endpoint.py +3 -3
- biolib/_internal/file_utils.py +48 -0
- biolib/_internal/index/__init__.py +1 -0
- biolib/_internal/index/index.py +18 -0
- biolib/_internal/lfs/cache.py +4 -2
- biolib/_internal/push_application.py +89 -23
- biolib/_internal/runtime.py +2 -0
- biolib/_internal/string_utils.py +13 -0
- biolib/_internal/templates/copilot_template/.github/instructions/style-react-ts.instructions.md +47 -0
- biolib/_internal/templates/copilot_template/.github/prompts/biolib_onboard_repo.prompt.md +19 -0
- biolib/_internal/templates/gui_template/.yarnrc.yml +1 -0
- biolib/_internal/templates/gui_template/App.tsx +53 -0
- biolib/_internal/templates/gui_template/Dockerfile +28 -0
- biolib/_internal/templates/gui_template/biolib-sdk.ts +37 -0
- biolib/_internal/templates/gui_template/dev-data/output.json +7 -0
- biolib/_internal/templates/gui_template/index.css +5 -0
- biolib/_internal/templates/gui_template/index.html +13 -0
- biolib/_internal/templates/gui_template/index.tsx +10 -0
- biolib/_internal/templates/gui_template/package.json +27 -0
- biolib/_internal/templates/gui_template/tsconfig.json +24 -0
- biolib/_internal/templates/gui_template/vite-plugin-dev-data.ts +49 -0
- biolib/_internal/templates/gui_template/vite.config.mts +9 -0
- biolib/_internal/templates/init_template/.biolib/config.yml +1 -0
- biolib/_internal/templates/init_template/.github/workflows/biolib.yml +6 -1
- biolib/_internal/templates/init_template/Dockerfile +2 -0
- biolib/_internal/templates/init_template/run.sh +1 -0
- biolib/_internal/templates/templates.py +9 -1
- biolib/_internal/utils/__init__.py +25 -0
- biolib/_internal/utils/job_url.py +33 -0
- biolib/_internal/utils/multinode.py +12 -14
- biolib/_runtime/runtime.py +15 -2
- biolib/_session/session.py +7 -5
- biolib/_shared/__init__.py +0 -0
- biolib/_shared/types/__init__.py +69 -0
- biolib/_shared/types/account.py +12 -0
- biolib/_shared/types/account_member.py +8 -0
- biolib/{_internal → _shared}/types/experiment.py +1 -0
- biolib/_shared/types/resource.py +17 -0
- biolib/_shared/types/resource_deploy_key.py +11 -0
- biolib/{_internal → _shared}/types/resource_permission.py +1 -1
- biolib/{_internal → _shared}/types/user.py +5 -5
- biolib/_shared/utils/__init__.py +7 -0
- biolib/_shared/utils/resource_uri.py +75 -0
- biolib/api/client.py +1 -1
- biolib/app/app.py +96 -45
- biolib/biolib_api_client/app_types.py +1 -0
- biolib/biolib_api_client/biolib_app_api.py +26 -0
- biolib/biolib_binary_format/module_input.py +8 -0
- biolib/biolib_binary_format/remote_endpoints.py +3 -3
- biolib/biolib_binary_format/remote_stream_seeker.py +39 -25
- biolib/biolib_logging.py +1 -1
- biolib/cli/__init__.py +2 -1
- biolib/cli/auth.py +4 -16
- biolib/cli/data_record.py +17 -0
- biolib/cli/index.py +32 -0
- biolib/cli/init.py +93 -11
- biolib/cli/lfs.py +1 -1
- biolib/cli/run.py +1 -1
- biolib/cli/start.py +14 -1
- biolib/compute_node/job_worker/executors/docker_executor.py +31 -9
- biolib/compute_node/job_worker/executors/docker_types.py +1 -1
- biolib/compute_node/job_worker/executors/types.py +6 -5
- biolib/compute_node/job_worker/job_storage.py +2 -1
- biolib/compute_node/job_worker/job_worker.py +155 -90
- biolib/compute_node/job_worker/large_file_system.py +2 -6
- biolib/compute_node/job_worker/network_alloc.py +99 -0
- biolib/compute_node/job_worker/network_buffer.py +240 -0
- biolib/compute_node/job_worker/utilization_reporter_thread.py +2 -2
- biolib/compute_node/remote_host_proxy.py +135 -67
- biolib/compute_node/utils.py +2 -0
- biolib/compute_node/webserver/compute_node_results_proxy.py +188 -0
- biolib/compute_node/webserver/proxy_utils.py +28 -0
- biolib/compute_node/webserver/webserver.py +64 -19
- biolib/experiments/experiment.py +98 -16
- biolib/jobs/job.py +128 -31
- biolib/jobs/job_result.py +73 -33
- biolib/jobs/types.py +1 -0
- biolib/sdk/__init__.py +17 -2
- biolib/typing_utils.py +1 -1
- biolib/utils/cache_state.py +2 -2
- biolib/utils/seq_util.py +1 -1
- {pybiolib-1.2.911.dist-info → pybiolib-1.2.1642.dist-info}/METADATA +4 -2
- pybiolib-1.2.1642.dist-info/RECORD +180 -0
- {pybiolib-1.2.911.dist-info → pybiolib-1.2.1642.dist-info}/WHEEL +1 -1
- biolib/_internal/llm_instructions/.github/instructions/style-react-ts.instructions.md +0 -22
- biolib/_internal/types/__init__.py +0 -6
- biolib/_internal/types/account.py +0 -10
- biolib/utils/app_uri.py +0 -57
- pybiolib-1.2.911.dist-info/RECORD +0 -150
- /biolib/{_internal/llm_instructions → _index}/__init__.py +0 -0
- /biolib/_internal/{llm_instructions → templates/copilot_template}/.github/instructions/general-app-knowledge.instructions.md +0 -0
- /biolib/_internal/{llm_instructions → templates/copilot_template}/.github/instructions/style-general.instructions.md +0 -0
- /biolib/_internal/{llm_instructions → templates/copilot_template}/.github/instructions/style-python.instructions.md +0 -0
- /biolib/_internal/{llm_instructions → templates/copilot_template}/.github/prompts/biolib_app_inputs.prompt.md +0 -0
- /biolib/_internal/{llm_instructions → templates/copilot_template}/.github/prompts/biolib_run_apps.prompt.md +0 -0
- /biolib/{_internal → _shared}/types/app.py +0 -0
- /biolib/{_internal → _shared}/types/data_record.py +0 -0
- /biolib/{_internal → _shared}/types/file_node.py +0 -0
- /biolib/{_internal → _shared}/types/push.py +0 -0
- /biolib/{_internal/types/resource.py → _shared/types/resource_types.py} +0 -0
- /biolib/{_internal → _shared}/types/resource_version.py +0 -0
- /biolib/{_internal → _shared}/types/result.py +0 -0
- /biolib/{_internal → _shared}/types/typing.py +0 -0
- {pybiolib-1.2.911.dist-info → pybiolib-1.2.1642.dist-info}/entry_points.txt +0 -0
- {pybiolib-1.2.911.dist-info → pybiolib-1.2.1642.dist-info/licenses}/LICENSE +0 -0
biolib/__init__.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# ruff: noqa: I001
|
|
1
2
|
# Imports to hide
|
|
2
3
|
import os
|
|
3
4
|
from urllib.parse import urlparse as _urlparse
|
|
@@ -15,6 +16,7 @@ from biolib.jobs.job import Result as _Result
|
|
|
15
16
|
from biolib import user as _user
|
|
16
17
|
from biolib.typing_utils import List, Optional, cast as _cast
|
|
17
18
|
from biolib._data_record.data_record import DataRecord as _DataRecord
|
|
19
|
+
from biolib._internal.utils.job_url import parse_result_id_or_url as _parse_result_id_or_url
|
|
18
20
|
|
|
19
21
|
import biolib.api
|
|
20
22
|
import biolib.app
|
|
@@ -22,7 +24,6 @@ import biolib.cli
|
|
|
22
24
|
import biolib.sdk
|
|
23
25
|
import biolib.utils
|
|
24
26
|
|
|
25
|
-
|
|
26
27
|
# ------------------------------------ Function definitions for public Python API ------------------------------------
|
|
27
28
|
|
|
28
29
|
|
|
@@ -83,43 +84,65 @@ def search(
|
|
|
83
84
|
|
|
84
85
|
|
|
85
86
|
def get_job(job_id: str, job_token: Optional[str] = None) -> _Result:
|
|
86
|
-
r"""Get a job by its ID.
|
|
87
|
+
r"""Get a job by its ID or full URL.
|
|
87
88
|
|
|
88
89
|
Args:
|
|
89
|
-
job_id (str): The UUID of the job to retrieve
|
|
90
|
+
job_id (str): The UUID of the job to retrieve, or a full URL to the job.
|
|
91
|
+
Can be either:
|
|
92
|
+
- Job UUID (e.g., 'abc123')
|
|
93
|
+
- Full URL (e.g., 'https://biolib.com/result/abc123/?token=xyz789')
|
|
94
|
+
- Full URL with token parameter (e.g., 'biolib.com/result/abc123/token=xyz789')
|
|
90
95
|
job_token (str, optional): Authentication token for accessing the job.
|
|
91
96
|
Only needed for jobs that aren't owned by the current user.
|
|
97
|
+
If the URL contains a token, this parameter is ignored.
|
|
92
98
|
|
|
93
99
|
Returns:
|
|
94
100
|
Job: The job object
|
|
95
101
|
|
|
96
102
|
Example::
|
|
97
103
|
|
|
104
|
+
>>> # Get by UUID
|
|
98
105
|
>>> job = biolib.get_job('abc123')
|
|
99
|
-
>>> #
|
|
106
|
+
>>> # Get with explicit token
|
|
100
107
|
>>> job = biolib.get_job('abc123', job_token='xyz789')
|
|
108
|
+
>>> # Get by full URL with token
|
|
109
|
+
>>> job = biolib.get_job('https://biolib.com/result/abc123/?token=xyz789')
|
|
110
|
+
>>> # Get by URL with inline token format
|
|
111
|
+
>>> job = biolib.get_job('biolib.com/result/abc123/token=xyz789')
|
|
101
112
|
"""
|
|
102
|
-
|
|
113
|
+
uuid, token = _parse_result_id_or_url(job_id, job_token)
|
|
114
|
+
return _Result.create_from_uuid(uuid=uuid, auth_token=token)
|
|
103
115
|
|
|
104
116
|
|
|
105
117
|
def get_result(result_id: str, result_token: Optional[str] = None) -> _Result:
|
|
106
|
-
r"""Get a result by its ID.
|
|
118
|
+
r"""Get a result by its ID or full URL.
|
|
107
119
|
|
|
108
120
|
Args:
|
|
109
|
-
result_id (str): The UUID of the result to retrieve
|
|
121
|
+
result_id (str): The UUID of the result to retrieve, or a full URL to the result.
|
|
122
|
+
Can be either:
|
|
123
|
+
- Result UUID (e.g., 'abc123')
|
|
124
|
+
- Full URL (e.g., 'https://biolib.com/result/abc123/?token=xyz789')
|
|
125
|
+
- Full URL with token parameter (e.g., 'biolib.com/result/abc123/token=xyz789')
|
|
110
126
|
result_token (str, optional): Authentication token for accessing the result.
|
|
111
|
-
Only needed for
|
|
127
|
+
Only needed for results that aren't owned by the current user.
|
|
128
|
+
If the URL contains a token, this parameter is ignored.
|
|
112
129
|
|
|
113
130
|
Returns:
|
|
114
131
|
Result: The result object
|
|
115
132
|
|
|
116
133
|
Example::
|
|
117
134
|
|
|
135
|
+
>>> # Get by UUID
|
|
118
136
|
>>> result = biolib.get_result('abc123')
|
|
119
|
-
>>> #
|
|
137
|
+
>>> # Get with explicit token
|
|
120
138
|
>>> result = biolib.get_result('abc123', result_token='xyz789')
|
|
139
|
+
>>> # Get by full URL with token
|
|
140
|
+
>>> result = biolib.get_result('https://biolib.com/result/abc123/?token=xyz789')
|
|
141
|
+
>>> # Get by URL with inline token format
|
|
142
|
+
>>> result = biolib.get_result('biolib.com/result/abc123/token=xyz789')
|
|
121
143
|
"""
|
|
122
|
-
|
|
144
|
+
uuid, token = _parse_result_id_or_url(result_id, result_token)
|
|
145
|
+
return _Result.create_from_uuid(uuid=uuid, auth_token=token)
|
|
123
146
|
|
|
124
147
|
|
|
125
148
|
def get_data_record(uri: str) -> _DataRecord:
|
|
@@ -6,7 +6,6 @@ from struct import Struct
|
|
|
6
6
|
from typing import Callable, Dict, Iterable, List, Optional, Union, cast
|
|
7
7
|
|
|
8
8
|
from biolib import api
|
|
9
|
-
from biolib._internal import types
|
|
10
9
|
from biolib._internal.data_record import get_data_record_state_from_uri
|
|
11
10
|
from biolib._internal.data_record.data_record import validate_sqlite_v1
|
|
12
11
|
from biolib._internal.data_record.push_data import (
|
|
@@ -15,14 +14,15 @@ from biolib._internal.data_record.push_data import (
|
|
|
15
14
|
)
|
|
16
15
|
from biolib._internal.data_record.remote_storage_endpoint import DataRecordRemoteStorageEndpoint
|
|
17
16
|
from biolib._internal.http_client import HttpClient
|
|
18
|
-
from biolib.
|
|
17
|
+
from biolib._shared import types
|
|
18
|
+
from biolib._shared.types import ZipFileNodeDict
|
|
19
|
+
from biolib._shared.utils import parse_resource_uri
|
|
19
20
|
from biolib.api import client as api_client
|
|
20
21
|
from biolib.biolib_api_client import BiolibApiClient
|
|
21
22
|
from biolib.biolib_api_client.lfs_types import DataRecordInfo, DataRecordVersion, DataRecordVersionInfo
|
|
22
23
|
from biolib.biolib_binary_format import LazyLoadedFile
|
|
23
24
|
from biolib.biolib_binary_format.utils import RemoteIndexableBuffer
|
|
24
25
|
from biolib.biolib_logging import logger
|
|
25
|
-
from biolib.utils.app_uri import parse_app_uri
|
|
26
26
|
|
|
27
27
|
PathFilter = Union[str, List[str], Callable[[str], bool]]
|
|
28
28
|
|
|
@@ -44,11 +44,11 @@ class DataRecord:
|
|
|
44
44
|
|
|
45
45
|
@property
|
|
46
46
|
def name(self) -> str:
|
|
47
|
-
uri_parsed =
|
|
48
|
-
if not uri_parsed['
|
|
47
|
+
uri_parsed = parse_resource_uri(self._state['resource_uri'], use_account_as_name_default=False)
|
|
48
|
+
if not uri_parsed['resource_name']:
|
|
49
49
|
raise ValueError('Expected parameter "resource_uri" to contain resource name')
|
|
50
50
|
|
|
51
|
-
return uri_parsed['
|
|
51
|
+
return uri_parsed['resource_name']
|
|
52
52
|
|
|
53
53
|
def list_files(
|
|
54
54
|
self,
|
|
@@ -142,8 +142,8 @@ class DataRecord:
|
|
|
142
142
|
BiolibApiClient.assert_is_signed_in(authenticated_action_description='create a Data Record')
|
|
143
143
|
if data_path is not None:
|
|
144
144
|
assert os.path.isdir(data_path), f'The path "{data_path}" is not a directory.'
|
|
145
|
-
uri_parsed =
|
|
146
|
-
if uri_parsed['
|
|
145
|
+
uri_parsed = parse_resource_uri(destination, use_account_as_name_default=False)
|
|
146
|
+
if uri_parsed['resource_name_normalized']:
|
|
147
147
|
data_record_uri = destination
|
|
148
148
|
else:
|
|
149
149
|
record_name = 'data-record-' + datetime.now().isoformat().split('.')[0].replace(':', '-')
|
|
@@ -173,10 +173,10 @@ class DataRecord:
|
|
|
173
173
|
'resource_type': 'data-record',
|
|
174
174
|
}
|
|
175
175
|
if uri:
|
|
176
|
-
uri_parsed =
|
|
176
|
+
uri_parsed = parse_resource_uri(uri, use_account_as_name_default=False)
|
|
177
177
|
params['account_handle'] = uri_parsed['account_handle_normalized']
|
|
178
|
-
if uri_parsed['
|
|
179
|
-
params['app_name'] = uri_parsed['
|
|
178
|
+
if uri_parsed['resource_name_normalized']:
|
|
179
|
+
params['app_name'] = uri_parsed['resource_name_normalized']
|
|
180
180
|
|
|
181
181
|
results = api_client.get(path='/apps/', params=params).json()['results']
|
|
182
182
|
if count is None and len(results) == max_page_size:
|
|
@@ -284,3 +284,16 @@ class DataRecord:
|
|
|
284
284
|
|
|
285
285
|
def _get_detailed_dict(self) -> types.DataRecordDetailedDict:
|
|
286
286
|
return cast(types.DataRecordDetailedDict, api_client.get(f'/resources/data-records/{self.uuid}/').json())
|
|
287
|
+
|
|
288
|
+
def delete(self) -> None:
|
|
289
|
+
"""Delete the data record.
|
|
290
|
+
|
|
291
|
+
Example::
|
|
292
|
+
>>> record = DataRecord.get_by_uri("account/data-record")
|
|
293
|
+
>>> record.delete()
|
|
294
|
+
"""
|
|
295
|
+
try:
|
|
296
|
+
api_client.delete(path=f'/apps/{self.uuid}/')
|
|
297
|
+
logger.info(f'Data record {self.uri} deleted')
|
|
298
|
+
except Exception as error:
|
|
299
|
+
raise Exception(f'Failed to delete data record {self.uri} due to: {error}') from error
|
biolib/_index/index.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from typing import Any, Dict
|
|
3
|
+
|
|
4
|
+
from biolib import api
|
|
5
|
+
from biolib._index.types import IndexInfo
|
|
6
|
+
from biolib._internal.index import get_index_from_uri
|
|
7
|
+
from biolib.biolib_api_client import BiolibApiClient
|
|
8
|
+
from biolib.biolib_logging import logger
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Index:
|
|
12
|
+
def __init__(self, _internal_state: IndexInfo):
|
|
13
|
+
self._state = _internal_state
|
|
14
|
+
|
|
15
|
+
def __repr__(self) -> str:
|
|
16
|
+
return f'Index: {self._state["resource_uri"]}'
|
|
17
|
+
|
|
18
|
+
@property
|
|
19
|
+
def uri(self) -> str:
|
|
20
|
+
return self._state['resource_uri']
|
|
21
|
+
|
|
22
|
+
@property
|
|
23
|
+
def id(self) -> str:
|
|
24
|
+
return f"{self._state['group_uuid']}.{self._state['resource_uuid']}".replace("-", "_")
|
|
25
|
+
|
|
26
|
+
@staticmethod
|
|
27
|
+
def get_by_uri(uri: str) -> 'Index':
|
|
28
|
+
return Index(_internal_state=get_index_from_uri(uri))
|
|
29
|
+
|
|
30
|
+
@staticmethod
|
|
31
|
+
def create(uri: str, config: Dict[str, Any]) -> str:
|
|
32
|
+
BiolibApiClient.assert_is_signed_in(authenticated_action_description='create an Index')
|
|
33
|
+
|
|
34
|
+
response = api.client.post(
|
|
35
|
+
path='/resources/indexes/',
|
|
36
|
+
data={
|
|
37
|
+
'uri': uri,
|
|
38
|
+
'index_config': config,
|
|
39
|
+
},
|
|
40
|
+
)
|
|
41
|
+
result = response.json()
|
|
42
|
+
created_uri: str = result['uri']
|
|
43
|
+
logger.info(f"Successfully created Index '{created_uri}'")
|
|
44
|
+
return created_uri
|
|
45
|
+
|
|
46
|
+
@staticmethod
|
|
47
|
+
def create_from_config_file(uri: str, config_path: str) -> str:
|
|
48
|
+
with open(config_path) as config_file:
|
|
49
|
+
index_config = json.load(config_file)
|
|
50
|
+
|
|
51
|
+
return Index.create(uri=uri, config=index_config)
|
biolib/_index/types.py
ADDED
|
@@ -2,10 +2,10 @@ import os
|
|
|
2
2
|
import shutil
|
|
3
3
|
import sys
|
|
4
4
|
|
|
5
|
-
from biolib._internal import
|
|
5
|
+
from biolib._internal.templates import templates
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
def add_copilot_prompts(force: bool,
|
|
8
|
+
def add_copilot_prompts(force: bool, silent: bool = False) -> None:
|
|
9
9
|
current_working_directory = os.getcwd()
|
|
10
10
|
config_file_path = f'{current_working_directory}/.biolib/config.yml'
|
|
11
11
|
if not os.path.exists(config_file_path):
|
|
@@ -14,7 +14,7 @@ Error: Current directory has not been initialized as a BioLib application.
|
|
|
14
14
|
Please run the \"biolib init\" command first"""
|
|
15
15
|
print(err_string, file=sys.stderr)
|
|
16
16
|
exit(1)
|
|
17
|
-
source_path = os.path.join(
|
|
17
|
+
source_path = os.path.join(templates.copilot_template(), '.github')
|
|
18
18
|
destination_path = os.path.join(current_working_directory, '.github')
|
|
19
19
|
|
|
20
20
|
conflicting_files = []
|
|
@@ -23,8 +23,6 @@ Error: Current directory has not been initialized as a BioLib application.
|
|
|
23
23
|
relative_dir = os.path.relpath(root, source_path)
|
|
24
24
|
destination_dir = os.path.join(destination_path, relative_dir)
|
|
25
25
|
for filename in filenames:
|
|
26
|
-
if 'style' in filename and not style:
|
|
27
|
-
continue
|
|
28
26
|
source_file = os.path.join(root, filename)
|
|
29
27
|
destination_file = os.path.join(destination_dir, filename)
|
|
30
28
|
if os.path.exists(destination_file) and not force:
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import shutil
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
from biolib._internal.templates import templates
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def add_gui_files(force=False, silent=False) -> None:
|
|
9
|
+
cwd = os.getcwd()
|
|
10
|
+
template_dir = templates.gui_template()
|
|
11
|
+
|
|
12
|
+
root_files = ['package.json', 'Dockerfile', 'index.html', 'vite.config.mts', '.yarnrc.yml']
|
|
13
|
+
|
|
14
|
+
conflicting_files = []
|
|
15
|
+
|
|
16
|
+
# Copy root_files to init_template root and rest to subdirectory
|
|
17
|
+
for root, _, filenames in os.walk(template_dir):
|
|
18
|
+
relative_dir = os.path.relpath(root, template_dir)
|
|
19
|
+
|
|
20
|
+
for filename in filenames:
|
|
21
|
+
if filename in root_files:
|
|
22
|
+
destination_dir = cwd
|
|
23
|
+
else:
|
|
24
|
+
if relative_dir == '.':
|
|
25
|
+
destination_dir = os.path.join(cwd, 'gui')
|
|
26
|
+
else:
|
|
27
|
+
destination_dir = os.path.join(cwd, 'gui', relative_dir)
|
|
28
|
+
|
|
29
|
+
source_file = os.path.join(root, filename)
|
|
30
|
+
destination_file = os.path.join(destination_dir, filename)
|
|
31
|
+
|
|
32
|
+
if filename == 'Dockerfile':
|
|
33
|
+
force = True
|
|
34
|
+
|
|
35
|
+
if os.path.exists(destination_file) and not force:
|
|
36
|
+
with open(source_file, 'rb') as fsrc, open(destination_file, 'rb') as fdest:
|
|
37
|
+
if fsrc.read() != fdest.read():
|
|
38
|
+
conflicting_files.append(os.path.relpath(destination_file, cwd))
|
|
39
|
+
else:
|
|
40
|
+
os.makedirs(destination_dir, exist_ok=True)
|
|
41
|
+
shutil.copy2(source_file, destination_file)
|
|
42
|
+
|
|
43
|
+
gitignore_path = os.path.join(cwd, '.gitignore')
|
|
44
|
+
with open(gitignore_path, 'a') as gitignore_file:
|
|
45
|
+
gitignore_file.write('\n# gui\n')
|
|
46
|
+
gitignore_file.write('.yarn\n')
|
|
47
|
+
gitignore_file.write('dist\n')
|
|
48
|
+
gitignore_file.write('yarn.lock\n')
|
|
49
|
+
gitignore_file.write('tsconfig.tsbuildinfo\n')
|
|
50
|
+
gitignore_file.write('node_modules\n')
|
|
51
|
+
|
|
52
|
+
if conflicting_files:
|
|
53
|
+
print('The following files were not overwritten. Use --force to override them:', file=sys.stderr)
|
|
54
|
+
for conflicting_file in list(set(conflicting_files)):
|
|
55
|
+
print(f' {conflicting_file}', file=sys.stderr)
|
|
56
|
+
exit(1)
|
|
57
|
+
|
|
58
|
+
if not silent:
|
|
59
|
+
print('gui files added to project root and gui/ subdirectory')
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import sqlite3
|
|
2
2
|
from pathlib import Path
|
|
3
3
|
|
|
4
|
-
from biolib.
|
|
4
|
+
from biolib._shared.types import SqliteV1DatabaseSchema
|
|
5
5
|
from biolib.api import client as api_client
|
|
6
6
|
from biolib.biolib_api_client import AppGetResponse
|
|
7
7
|
from biolib.biolib_api_client.biolib_app_api import _get_app_uri_from_str
|
|
@@ -2,9 +2,9 @@ import os
|
|
|
2
2
|
|
|
3
3
|
from biolib import utils
|
|
4
4
|
from biolib._internal.file_utils import get_files_and_size_of_directory, get_iterable_zip_stream
|
|
5
|
-
from biolib._internal.types.typing import List, Optional, Tuple
|
|
6
5
|
from biolib.biolib_errors import BioLibError
|
|
7
6
|
from biolib.biolib_logging import logger
|
|
7
|
+
from biolib.typing_utils import List, Optional, Tuple
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
def validate_data_path_and_get_files_and_size_of_directory(data_path: str) -> Tuple[List[str], int]:
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import os
|
|
2
|
-
from datetime import datetime, timedelta
|
|
2
|
+
from datetime import datetime, timedelta, timezone
|
|
3
3
|
from urllib.parse import urlparse
|
|
4
4
|
|
|
5
5
|
from biolib.api import client as api_client
|
|
@@ -16,7 +16,7 @@ class DataRecordRemoteStorageEndpoint(RemoteEndpoint):
|
|
|
16
16
|
self._presigned_url: Optional[str] = None
|
|
17
17
|
|
|
18
18
|
def get_remote_url(self) -> str:
|
|
19
|
-
if not self._presigned_url or not self._expires_at or datetime.
|
|
19
|
+
if not self._presigned_url or not self._expires_at or datetime.now(timezone.utc) > self._expires_at:
|
|
20
20
|
lfs_version: DataRecordVersion = api_client.get(
|
|
21
21
|
path=f'/lfs/versions/{self._resource_version_uuid}/',
|
|
22
22
|
).json()
|
|
@@ -29,7 +29,7 @@ class DataRecordRemoteStorageEndpoint(RemoteEndpoint):
|
|
|
29
29
|
else:
|
|
30
30
|
self._presigned_url = lfs_version['presigned_download_url']
|
|
31
31
|
|
|
32
|
-
self._expires_at = datetime.
|
|
32
|
+
self._expires_at = datetime.now(timezone.utc) + timedelta(minutes=8)
|
|
33
33
|
logger.debug(
|
|
34
34
|
f'DataRecord "{self._resource_version_uuid}" fetched presigned URL '
|
|
35
35
|
f'with expiry at {self._expires_at.isoformat()}'
|
biolib/_internal/file_utils.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import hashlib
|
|
1
2
|
import io
|
|
2
3
|
import os
|
|
4
|
+
import posixpath
|
|
3
5
|
import zipfile as zf
|
|
4
6
|
from pathlib import Path
|
|
5
7
|
|
|
@@ -75,3 +77,49 @@ def get_iterable_zip_stream(files: List[str], chunk_size: int) -> Iterator[bytes
|
|
|
75
77
|
if len(chunk) == 0:
|
|
76
78
|
break
|
|
77
79
|
yield chunk
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def path_to_renamed_path(path_str: str, prefix_with_slash: bool = True) -> str:
|
|
83
|
+
"""
|
|
84
|
+
Normalize file paths consistently:
|
|
85
|
+
- If path contains '..' (relative path going up), convert to absolute path
|
|
86
|
+
- If relative path not containing '..', keep as is, but prepend / if prefix_with_slash=True
|
|
87
|
+
- If absolute path that is subpath of current directory, convert to relative path
|
|
88
|
+
- If absolute path not subpath of current directory, hash the folder path and keep filename
|
|
89
|
+
"""
|
|
90
|
+
path = Path(path_str)
|
|
91
|
+
current_dir = Path.cwd()
|
|
92
|
+
|
|
93
|
+
if '..' in path.parts:
|
|
94
|
+
resolved_path = path.resolve()
|
|
95
|
+
try:
|
|
96
|
+
relative_path = resolved_path.relative_to(current_dir)
|
|
97
|
+
result = str(relative_path)
|
|
98
|
+
except ValueError:
|
|
99
|
+
folder_path = str(resolved_path.parent)
|
|
100
|
+
filename = resolved_path.name
|
|
101
|
+
folder_hash = hashlib.md5(folder_path.encode()).hexdigest()[:6]
|
|
102
|
+
result = f'/{folder_hash}/{filename}'
|
|
103
|
+
elif path.is_absolute():
|
|
104
|
+
try:
|
|
105
|
+
resolved_path = path.resolve()
|
|
106
|
+
relative_path = resolved_path.relative_to(current_dir)
|
|
107
|
+
result = str(relative_path)
|
|
108
|
+
except ValueError:
|
|
109
|
+
folder_path = str(path.parent)
|
|
110
|
+
filename = path.name
|
|
111
|
+
folder_hash = hashlib.md5(folder_path.encode()).hexdigest()[:6]
|
|
112
|
+
result = f'/{folder_hash}/{filename}'
|
|
113
|
+
else:
|
|
114
|
+
result = path_str
|
|
115
|
+
|
|
116
|
+
if prefix_with_slash:
|
|
117
|
+
if not result.startswith('/'):
|
|
118
|
+
result = '/' + result
|
|
119
|
+
# Normalize to handle cases like '/./mydir' -> '/mydir' and remove trailing slashes.
|
|
120
|
+
# Required because downstream Mappings class does exact string-prefix matching.
|
|
121
|
+
return posixpath.normpath(result)
|
|
122
|
+
else:
|
|
123
|
+
if result.startswith('/'):
|
|
124
|
+
result = result[1:]
|
|
125
|
+
return posixpath.normpath(result)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .index import get_index_from_uri
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from typing import Any, Dict
|
|
2
|
+
|
|
3
|
+
from biolib._index.types import IndexInfo
|
|
4
|
+
from biolib.api import client as api_client
|
|
5
|
+
from biolib.biolib_api_client.biolib_app_api import _get_app_uri_from_str
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def get_index_from_uri(uri: str) -> IndexInfo:
|
|
9
|
+
normalized_uri = _get_app_uri_from_str(uri)
|
|
10
|
+
app_response: Dict[str, Any] = api_client.get(path='/app/', params={'uri': normalized_uri}).json()
|
|
11
|
+
resource_uri = app_response['app_version']['app_uri']
|
|
12
|
+
if app_response['app']['type'] != 'index':
|
|
13
|
+
raise Exception(f'Resource "{resource_uri}" is not an Index')
|
|
14
|
+
return IndexInfo(
|
|
15
|
+
resource_uri=app_response['app_version']['app_uri'],
|
|
16
|
+
resource_uuid=app_response['app']['public_id'],
|
|
17
|
+
group_uuid=app_response['app']['group_uuid'],
|
|
18
|
+
)
|
biolib/_internal/lfs/cache.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import subprocess
|
|
3
|
-
from datetime import datetime, timedelta
|
|
3
|
+
from datetime import datetime, timedelta, timezone
|
|
4
4
|
|
|
5
5
|
from biolib.biolib_logging import logger_no_user_data
|
|
6
6
|
from biolib.compute_node.job_worker.cache_state import LfsCacheState
|
|
@@ -9,7 +9,7 @@ from biolib.compute_node.job_worker.cache_state import LfsCacheState
|
|
|
9
9
|
def prune_lfs_cache(dry_run: bool) -> None:
|
|
10
10
|
logger_no_user_data.info(f'Pruning LFS cache (dry run = {dry_run})...')
|
|
11
11
|
|
|
12
|
-
current_time = datetime.
|
|
12
|
+
current_time = datetime.now(timezone.utc)
|
|
13
13
|
paths_to_delete = set()
|
|
14
14
|
|
|
15
15
|
with LfsCacheState() as state:
|
|
@@ -24,6 +24,8 @@ def prune_lfs_cache(dry_run: bool) -> None:
|
|
|
24
24
|
lfs_uuids_to_keep_in_state = set()
|
|
25
25
|
for lfs_uuid, lfs in state['large_file_systems'].items():
|
|
26
26
|
last_used_at = datetime.fromisoformat(lfs['last_used_at'])
|
|
27
|
+
if last_used_at.tzinfo is None:
|
|
28
|
+
last_used_at = last_used_at.replace(tzinfo=timezone.utc)
|
|
27
29
|
lfs_time_to_live_in_days = 60 if lfs['state'] == 'ready' else 7
|
|
28
30
|
|
|
29
31
|
if last_used_at < current_time - timedelta(days=lfs_time_to_live_in_days):
|