runnable 0.25.0__tar.gz → 0.27.0__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {runnable-0.25.0 → runnable-0.27.0}/PKG-INFO +4 -1
- runnable-0.25.0/extensions/catalog/file_system.py → runnable-0.27.0/extensions/catalog/any_path.py +33 -85
- runnable-0.27.0/extensions/catalog/file_system.py +52 -0
- runnable-0.27.0/extensions/catalog/minio.py +72 -0
- runnable-0.27.0/extensions/catalog/s3.py +11 -0
- {runnable-0.25.0 → runnable-0.27.0}/extensions/pipeline_executor/__init__.py +3 -34
- runnable-0.25.0/extensions/run_log_store/file_system.py → runnable-0.27.0/extensions/run_log_store/any_path.py +10 -51
- {runnable-0.25.0 → runnable-0.27.0}/extensions/run_log_store/chunked_fs.py +13 -9
- runnable-0.27.0/extensions/run_log_store/file_system.py +91 -0
- {runnable-0.25.0 → runnable-0.27.0}/extensions/run_log_store/generic_chunked.py +17 -11
- runnable-0.27.0/extensions/run_log_store/minio.py +111 -0
- {runnable-0.25.0 → runnable-0.27.0}/pyproject.toml +8 -1
- {runnable-0.25.0 → runnable-0.27.0}/runnable/catalog.py +8 -28
- {runnable-0.25.0 → runnable-0.27.0}/runnable/datastore.py +2 -2
- {runnable-0.25.0 → runnable-0.27.0}/runnable/executor.py +0 -17
- {runnable-0.25.0 → runnable-0.27.0}/runnable/tasks.py +1 -3
- {runnable-0.25.0 → runnable-0.27.0}/runnable/utils.py +21 -18
- {runnable-0.25.0 → runnable-0.27.0}/.gitignore +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/LICENSE +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/README.md +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/extensions/README.md +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/extensions/__init__.py +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/extensions/catalog/README.md +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/extensions/catalog/pyproject.toml +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/extensions/job_executor/README.md +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/extensions/job_executor/__init__.py +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/extensions/job_executor/k8s.py +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/extensions/job_executor/k8s_job_spec.yaml +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/extensions/job_executor/local.py +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/extensions/job_executor/local_container.py +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/extensions/job_executor/pyproject.toml +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/extensions/nodes/README.md +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/extensions/nodes/nodes.py +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/extensions/nodes/pyproject.toml +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/extensions/pipeline_executor/README.md +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/extensions/pipeline_executor/argo.py +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/extensions/pipeline_executor/local.py +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/extensions/pipeline_executor/local_container.py +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/extensions/pipeline_executor/mocked.py +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/extensions/pipeline_executor/pyproject.toml +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/extensions/pipeline_executor/retry.py +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/extensions/run_log_store/README.md +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/extensions/run_log_store/__init__.py +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/extensions/run_log_store/db/implementation_FF.py +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/extensions/run_log_store/db/integration_FF.py +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/extensions/run_log_store/pyproject.toml +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/extensions/secrets/README.md +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/extensions/secrets/dotenv.py +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/extensions/secrets/pyproject.toml +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/runnable/__init__.py +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/runnable/cli.py +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/runnable/context.py +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/runnable/defaults.py +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/runnable/entrypoints.py +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/runnable/exceptions.py +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/runnable/graph.py +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/runnable/names.py +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/runnable/nodes.py +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/runnable/parameters.py +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/runnable/pickler.py +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/runnable/sdk.py +0 -0
- {runnable-0.25.0 → runnable-0.27.0}/runnable/secrets.py +0 -0
@@ -1,12 +1,13 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: runnable
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.27.0
|
4
4
|
Summary: Add your description here
|
5
5
|
Author-email: "Vammi, Vijay" <vijay.vammi@astrazeneca.com>
|
6
6
|
License-File: LICENSE
|
7
7
|
Requires-Python: >=3.10
|
8
8
|
Requires-Dist: click-plugins>=1.1.1
|
9
9
|
Requires-Dist: click<=8.1.3
|
10
|
+
Requires-Dist: cloudpathlib>=0.20.0
|
10
11
|
Requires-Dist: dill>=0.3.9
|
11
12
|
Requires-Dist: pydantic>=2.10.3
|
12
13
|
Requires-Dist: python-dotenv>=1.0.1
|
@@ -23,6 +24,8 @@ Provides-Extra: k8s
|
|
23
24
|
Requires-Dist: kubernetes>=31.0.0; extra == 'k8s'
|
24
25
|
Provides-Extra: notebook
|
25
26
|
Requires-Dist: ploomber-engine>=0.0.33; extra == 'notebook'
|
27
|
+
Provides-Extra: s3
|
28
|
+
Requires-Dist: cloudpathlib[s3]; extra == 's3'
|
26
29
|
Description-Content-Type: text/markdown
|
27
30
|
|
28
31
|
|
runnable-0.25.0/extensions/catalog/file_system.py → runnable-0.27.0/extensions/catalog/any_path.py
RENAMED
@@ -1,17 +1,20 @@
|
|
1
1
|
import logging
|
2
2
|
import os
|
3
3
|
import shutil
|
4
|
+
from abc import abstractmethod
|
4
5
|
from pathlib import Path
|
5
|
-
from typing import Any, Dict, List
|
6
|
+
from typing import Any, Dict, List
|
7
|
+
|
8
|
+
from cloudpathlib import CloudPath
|
6
9
|
|
7
10
|
from runnable import defaults, utils
|
8
|
-
from runnable.catalog import BaseCatalog
|
11
|
+
from runnable.catalog import BaseCatalog
|
9
12
|
from runnable.datastore import DataCatalog
|
10
13
|
|
11
14
|
logger = logging.getLogger(defaults.LOGGER_NAME)
|
12
15
|
|
13
16
|
|
14
|
-
class
|
17
|
+
class AnyPathCatalog(BaseCatalog):
|
15
18
|
"""
|
16
19
|
A Catalog handler that uses the local file system for cataloging.
|
17
20
|
|
@@ -27,22 +30,24 @@ class FileSystemCatalog(BaseCatalog):
|
|
27
30
|
|
28
31
|
"""
|
29
32
|
|
30
|
-
|
31
|
-
|
33
|
+
@abstractmethod
|
34
|
+
def get_summary(self) -> Dict[str, Any]: ...
|
32
35
|
|
33
|
-
|
34
|
-
|
36
|
+
@abstractmethod
|
37
|
+
def upload_to_catalog(self, file: Path) -> None: ...
|
35
38
|
|
36
|
-
|
37
|
-
|
38
|
-
"Catalog Location": self.get_catalog_location(),
|
39
|
-
}
|
39
|
+
@abstractmethod
|
40
|
+
def download_from_catalog(self, file: Path | CloudPath) -> None: ...
|
40
41
|
|
41
|
-
|
42
|
+
@abstractmethod
|
43
|
+
def get_catalog_location(self) -> Path | CloudPath:
|
44
|
+
"""
|
45
|
+
For local file systems, this is the .catalog/run_id/compute_data_folder
|
46
|
+
For cloud systems, this is s3://bucket/run_id/compute_data_folder
|
47
|
+
"""
|
48
|
+
...
|
42
49
|
|
43
|
-
def get(
|
44
|
-
self, name: str, run_id: str, compute_data_folder: str = "", **kwargs
|
45
|
-
) -> List[DataCatalog]:
|
50
|
+
def get(self, name: str) -> List[DataCatalog]:
|
46
51
|
"""
|
47
52
|
Get the file by matching glob pattern to the name
|
48
53
|
|
@@ -56,29 +61,7 @@ class FileSystemCatalog(BaseCatalog):
|
|
56
61
|
Returns:
|
57
62
|
List(object) : A list of catalog objects
|
58
63
|
"""
|
59
|
-
|
60
|
-
f"Using the {self.service_name} catalog and trying to get {name} for run_id: {run_id}"
|
61
|
-
)
|
62
|
-
|
63
|
-
copy_to = self.compute_data_folder
|
64
|
-
if compute_data_folder:
|
65
|
-
copy_to = compute_data_folder
|
66
|
-
|
67
|
-
copy_to = Path(copy_to) # type: ignore
|
68
|
-
|
69
|
-
catalog_location = self.get_catalog_location()
|
70
|
-
run_catalog = Path(catalog_location) / run_id / copy_to
|
71
|
-
|
72
|
-
logger.debug(
|
73
|
-
f"Copying objects to {copy_to} from the run catalog location of {run_catalog}"
|
74
|
-
)
|
75
|
-
|
76
|
-
if not utils.does_dir_exist(run_catalog):
|
77
|
-
msg = (
|
78
|
-
f"Expected Catalog to be present at: {run_catalog} but not found.\n"
|
79
|
-
"Note: Please make sure that some data was put in the catalog before trying to get from it.\n"
|
80
|
-
)
|
81
|
-
raise Exception(msg)
|
64
|
+
run_catalog = self.get_catalog_location()
|
82
65
|
|
83
66
|
# Iterate through the contents of the run_catalog and copy the files that fit the name pattern
|
84
67
|
# We should also return a list of data hashes
|
@@ -97,34 +80,21 @@ class FileSystemCatalog(BaseCatalog):
|
|
97
80
|
if str(file).endswith(".execution.log"):
|
98
81
|
continue
|
99
82
|
|
100
|
-
|
83
|
+
self.download_from_catalog(file)
|
84
|
+
relative_file_path = file.relative_to(run_catalog) # type: ignore
|
101
85
|
|
102
86
|
data_catalog = run_log_store.create_data_catalog(str(relative_file_path))
|
103
|
-
data_catalog.catalog_handler_location = catalog_location
|
104
87
|
data_catalog.catalog_relative_path = str(relative_file_path)
|
105
|
-
data_catalog.data_hash = utils.get_data_hash(str(
|
88
|
+
data_catalog.data_hash = utils.get_data_hash(str(relative_file_path))
|
106
89
|
data_catalog.stage = "get"
|
107
90
|
data_catalogs.append(data_catalog)
|
108
91
|
|
109
|
-
# Make the directory in the data folder if required
|
110
|
-
Path(copy_to / relative_file_path.parent).mkdir(parents=True, exist_ok=True)
|
111
|
-
shutil.copy(file, copy_to / relative_file_path)
|
112
|
-
|
113
|
-
logger.info(f"Copied {file} from {run_catalog} to {copy_to}")
|
114
|
-
|
115
92
|
if not data_catalogs:
|
116
93
|
raise Exception(f"Did not find any files matching {name} in {run_catalog}")
|
117
94
|
|
118
95
|
return data_catalogs
|
119
96
|
|
120
|
-
def put(
|
121
|
-
self,
|
122
|
-
name: str,
|
123
|
-
run_id: str,
|
124
|
-
compute_data_folder: str = "",
|
125
|
-
synced_catalogs: Optional[List[DataCatalog]] = None,
|
126
|
-
**kwargs,
|
127
|
-
) -> List[DataCatalog]:
|
97
|
+
def put(self, name: str) -> List[DataCatalog]:
|
128
98
|
"""
|
129
99
|
Put the files matching the glob pattern into the catalog.
|
130
100
|
|
@@ -142,26 +112,16 @@ class FileSystemCatalog(BaseCatalog):
|
|
142
112
|
Returns:
|
143
113
|
List(object) : A list of catalog objects
|
144
114
|
"""
|
115
|
+
run_id = self._context.run_id
|
145
116
|
logger.info(
|
146
117
|
f"Using the {self.service_name} catalog and trying to put {name} for run_id: {run_id}"
|
147
118
|
)
|
148
119
|
|
149
|
-
copy_from = self.compute_data_folder
|
150
|
-
if compute_data_folder:
|
151
|
-
copy_from = compute_data_folder
|
152
|
-
copy_from = Path(copy_from) # type: ignore
|
153
|
-
|
154
|
-
catalog_location = self.get_catalog_location()
|
155
|
-
run_catalog = Path(catalog_location) / run_id
|
156
|
-
utils.safe_make_dir(run_catalog)
|
120
|
+
copy_from = Path(self.compute_data_folder)
|
157
121
|
|
158
|
-
|
159
|
-
f"Copying objects from {copy_from} to the run catalog location of {run_catalog}"
|
160
|
-
)
|
161
|
-
|
162
|
-
if not utils.does_dir_exist(copy_from):
|
122
|
+
if not copy_from.is_dir():
|
163
123
|
msg = (
|
164
|
-
f"Expected compute data folder to be present at: {
|
124
|
+
f"Expected compute data folder to be present at: {copy_from} but not found. \n"
|
165
125
|
"Note: runnable does not create the compute data folder for you. Please ensure that the "
|
166
126
|
"folder exists.\n"
|
167
127
|
)
|
@@ -169,8 +129,7 @@ class FileSystemCatalog(BaseCatalog):
|
|
169
129
|
|
170
130
|
# Iterate through the contents of copy_from and if the name matches, we move them to the run_catalog
|
171
131
|
# We should also return a list of datastore.DataCatalog items
|
172
|
-
|
173
|
-
glob_files = copy_from.glob(name) # type: ignore
|
132
|
+
glob_files = copy_from.glob(name)
|
174
133
|
logger.debug(
|
175
134
|
f"Glob identified {glob_files} as matches to from the compute data folder: {copy_from}"
|
176
135
|
)
|
@@ -182,10 +141,9 @@ class FileSystemCatalog(BaseCatalog):
|
|
182
141
|
# Need not add a data catalog for the folder
|
183
142
|
continue
|
184
143
|
|
185
|
-
relative_file_path = file.relative_to(
|
144
|
+
relative_file_path = file.relative_to(copy_from)
|
186
145
|
|
187
146
|
data_catalog = run_log_store.create_data_catalog(str(relative_file_path))
|
188
|
-
data_catalog.catalog_handler_location = catalog_location
|
189
147
|
data_catalog.catalog_relative_path = (
|
190
148
|
run_id + os.sep + str(relative_file_path)
|
191
149
|
)
|
@@ -193,18 +151,8 @@ class FileSystemCatalog(BaseCatalog):
|
|
193
151
|
data_catalog.stage = "put"
|
194
152
|
data_catalogs.append(data_catalog)
|
195
153
|
|
196
|
-
if
|
197
|
-
|
198
|
-
|
199
|
-
# Make the directory in the catalog if required
|
200
|
-
Path(run_catalog / relative_file_path.parent).mkdir(
|
201
|
-
parents=True, exist_ok=True
|
202
|
-
)
|
203
|
-
shutil.copy(file, run_catalog / relative_file_path)
|
204
|
-
else:
|
205
|
-
logger.info(
|
206
|
-
f"{data_catalog.name} was found to be unchanged, ignoring syncing"
|
207
|
-
)
|
154
|
+
# TODO: Think about syncing only if the file is changed
|
155
|
+
self.upload_to_catalog(file)
|
208
156
|
|
209
157
|
if not data_catalogs:
|
210
158
|
raise Exception(f"Did not find any files matching {name} in {copy_from}")
|
@@ -0,0 +1,52 @@
|
|
1
|
+
import logging
|
2
|
+
import shutil
|
3
|
+
from pathlib import Path
|
4
|
+
from typing import Any
|
5
|
+
|
6
|
+
from cloudpathlib import CloudPath
|
7
|
+
from pydantic import Field
|
8
|
+
|
9
|
+
from extensions.catalog.any_path import AnyPathCatalog
|
10
|
+
from runnable import defaults
|
11
|
+
|
12
|
+
logger = logging.getLogger(defaults.LOGGER_NAME)
|
13
|
+
|
14
|
+
|
15
|
+
class FileSystemCatalog(AnyPathCatalog):
|
16
|
+
service_name: str = "file-system"
|
17
|
+
|
18
|
+
catalog_location: str = Field(default=defaults.CATALOG_LOCATION_FOLDER)
|
19
|
+
|
20
|
+
def get_summary(self) -> dict[str, Any]:
|
21
|
+
return {
|
22
|
+
"compute_data_folder": self.compute_data_folder,
|
23
|
+
"catalog_location": self.catalog_location,
|
24
|
+
}
|
25
|
+
|
26
|
+
def get_catalog_location(self) -> Path:
|
27
|
+
run_id = self._context.run_id
|
28
|
+
return Path(self.catalog_location) / run_id / self.compute_data_folder
|
29
|
+
|
30
|
+
def download_from_catalog(self, file: Path | CloudPath) -> None:
|
31
|
+
assert isinstance(file, Path)
|
32
|
+
|
33
|
+
run_catalog = self.get_catalog_location()
|
34
|
+
relative_file_path = file.relative_to(run_catalog)
|
35
|
+
|
36
|
+
copy_to = self.compute_data_folder
|
37
|
+
# Make the directory in the data folder if required
|
38
|
+
Path(copy_to / relative_file_path.parent).mkdir(parents=True, exist_ok=True)
|
39
|
+
shutil.copy(file, copy_to / relative_file_path)
|
40
|
+
|
41
|
+
def upload_to_catalog(self, file: Path) -> None:
|
42
|
+
run_catalog = self.get_catalog_location()
|
43
|
+
run_catalog.mkdir(parents=True, exist_ok=True)
|
44
|
+
|
45
|
+
logger.debug(
|
46
|
+
f"Copying objects from {self.compute_data_folder} to the run catalog location of {run_catalog}"
|
47
|
+
)
|
48
|
+
|
49
|
+
relative_file_path = file.relative_to(self.compute_data_folder)
|
50
|
+
|
51
|
+
(run_catalog / relative_file_path.parent).mkdir(parents=True, exist_ok=True)
|
52
|
+
shutil.copy(file, run_catalog / relative_file_path)
|
@@ -0,0 +1,72 @@
|
|
1
|
+
import logging
|
2
|
+
from functools import lru_cache
|
3
|
+
from pathlib import Path
|
4
|
+
from typing import Any
|
5
|
+
|
6
|
+
from cloudpathlib import CloudPath, S3Client, S3Path
|
7
|
+
from pydantic import Field, SecretStr
|
8
|
+
|
9
|
+
from extensions.catalog.any_path import AnyPathCatalog
|
10
|
+
from runnable import defaults
|
11
|
+
|
12
|
+
logger = logging.getLogger(defaults.LOGGER_NAME)
|
13
|
+
|
14
|
+
|
15
|
+
@lru_cache
|
16
|
+
def get_minio_client(
|
17
|
+
endpoint_url: str, aws_access_key_id: str, aws_secret_access_key: str
|
18
|
+
) -> S3Client:
|
19
|
+
return S3Client(
|
20
|
+
endpoint_url=endpoint_url,
|
21
|
+
aws_access_key_id=aws_access_key_id,
|
22
|
+
aws_secret_access_key=aws_secret_access_key,
|
23
|
+
)
|
24
|
+
|
25
|
+
|
26
|
+
class MinioCatalog(AnyPathCatalog):
|
27
|
+
service_name: str = "minio"
|
28
|
+
|
29
|
+
endpoint_url: str = Field(default="http://localhost:9002")
|
30
|
+
aws_access_key_id: SecretStr = SecretStr(secret_value="minioadmin")
|
31
|
+
aws_secret_access_key: SecretStr = SecretStr(secret_value="minioadmin")
|
32
|
+
bucket: str = "runnable"
|
33
|
+
|
34
|
+
def get_summary(self) -> dict[str, Any]:
|
35
|
+
return {
|
36
|
+
"service_name": self.service_name,
|
37
|
+
"compute_data_folder": self.compute_data_folder,
|
38
|
+
"endpoint_url": self.endpoint_url,
|
39
|
+
"bucket": self.bucket,
|
40
|
+
}
|
41
|
+
|
42
|
+
def get_catalog_location(self) -> S3Path:
|
43
|
+
run_id = self._context.run_id
|
44
|
+
|
45
|
+
return S3Path(
|
46
|
+
f"s3://{self.bucket}/{run_id}/{self.compute_data_folder}".strip("."),
|
47
|
+
client=get_minio_client(
|
48
|
+
self.endpoint_url,
|
49
|
+
self.aws_access_key_id.get_secret_value(),
|
50
|
+
self.aws_secret_access_key.get_secret_value(),
|
51
|
+
),
|
52
|
+
)
|
53
|
+
|
54
|
+
def download_from_catalog(self, file: Path | CloudPath) -> None:
|
55
|
+
assert isinstance(file, S3Path)
|
56
|
+
|
57
|
+
relative_file_path = file.relative_to(self.get_catalog_location())
|
58
|
+
|
59
|
+
file_to_download = Path(self.compute_data_folder) / relative_file_path
|
60
|
+
file_to_download.parent.mkdir(parents=True, exist_ok=True)
|
61
|
+
|
62
|
+
file.download_to(file_to_download)
|
63
|
+
|
64
|
+
def upload_to_catalog(self, file: Path) -> None:
|
65
|
+
run_catalog = self.get_catalog_location()
|
66
|
+
|
67
|
+
relative_file_path = file.relative_to(self.compute_data_folder)
|
68
|
+
(run_catalog / relative_file_path.parent).mkdir(parents=True, exist_ok=True)
|
69
|
+
|
70
|
+
file_in_cloud = run_catalog / file
|
71
|
+
assert isinstance(file_in_cloud, S3Path)
|
72
|
+
file_in_cloud.upload_from(file)
|
@@ -0,0 +1,11 @@
|
|
1
|
+
from cloudpathlib import S3Path
|
2
|
+
|
3
|
+
from extensions.catalog.any_path import AnyPathCatalog
|
4
|
+
|
5
|
+
|
6
|
+
class S3Catalog(AnyPathCatalog):
|
7
|
+
service_name: str = "s3"
|
8
|
+
|
9
|
+
def get_path(self, path: str) -> S3Path:
|
10
|
+
# TODO: Might need to assert the credentials are set
|
11
|
+
return S3Path(path)
|
@@ -151,54 +151,25 @@ class GenericPipelineExecutor(BasePipelineExecutor):
|
|
151
151
|
# Nothing to get/put from the catalog
|
152
152
|
return None
|
153
153
|
|
154
|
-
compute_data_folder = self.get_effective_compute_data_folder()
|
155
|
-
|
156
154
|
data_catalogs = []
|
157
155
|
for name_pattern in node_catalog_settings.get(stage) or []:
|
158
156
|
if stage == "get":
|
159
157
|
data_catalog = self._context.catalog_handler.get(
|
160
158
|
name=name_pattern,
|
161
|
-
run_id=self._context.run_id,
|
162
|
-
compute_data_folder=compute_data_folder,
|
163
159
|
)
|
164
160
|
|
165
161
|
elif stage == "put":
|
166
162
|
data_catalog = self._context.catalog_handler.put(
|
167
163
|
name=name_pattern,
|
168
|
-
run_id=self._context.run_id,
|
169
|
-
compute_data_folder=compute_data_folder,
|
170
|
-
synced_catalogs=synced_catalogs,
|
171
164
|
)
|
165
|
+
else:
|
166
|
+
raise Exception(f"Stage {stage} not supported")
|
172
167
|
|
173
168
|
logger.debug(f"Added data catalog: {data_catalog} to step log")
|
174
169
|
data_catalogs.extend(data_catalog)
|
175
170
|
|
176
171
|
return data_catalogs
|
177
172
|
|
178
|
-
def get_effective_compute_data_folder(self) -> str:
|
179
|
-
"""
|
180
|
-
Get the effective compute data folder for the given stage.
|
181
|
-
If there is nothing to catalog, we return None.
|
182
|
-
|
183
|
-
The default is the compute data folder of the catalog but this can be over-ridden by the node.
|
184
|
-
|
185
|
-
Args:
|
186
|
-
stage (str): The stage we are in the process of cataloging
|
187
|
-
|
188
|
-
|
189
|
-
Returns:
|
190
|
-
str: The compute data folder as defined by the node defaulting to catalog handler
|
191
|
-
"""
|
192
|
-
assert isinstance(self._context_node, BaseNode)
|
193
|
-
compute_data_folder = self._context.catalog_handler.compute_data_folder
|
194
|
-
|
195
|
-
catalog_settings = self._context_node._get_catalog_settings()
|
196
|
-
effective_compute_data_folder = (
|
197
|
-
catalog_settings.get("compute_data_folder", "") or compute_data_folder
|
198
|
-
)
|
199
|
-
|
200
|
-
return effective_compute_data_folder
|
201
|
-
|
202
173
|
@property
|
203
174
|
def step_attempt_number(self) -> int:
|
204
175
|
"""
|
@@ -219,9 +190,7 @@ class GenericPipelineExecutor(BasePipelineExecutor):
|
|
219
190
|
)
|
220
191
|
task_console.save_text(log_file_name)
|
221
192
|
# Put the log file in the catalog
|
222
|
-
self._context.catalog_handler.put(
|
223
|
-
name=log_file_name, run_id=self._context.run_id
|
224
|
-
)
|
193
|
+
self._context.catalog_handler.put(name=log_file_name)
|
225
194
|
os.remove(log_file_name)
|
226
195
|
|
227
196
|
def _execute_node(
|
@@ -1,15 +1,14 @@
|
|
1
|
-
import json
|
2
1
|
import logging
|
3
|
-
from
|
2
|
+
from abc import abstractmethod
|
4
3
|
from typing import Any, Dict
|
5
4
|
|
6
|
-
from runnable import defaults, exceptions
|
5
|
+
from runnable import defaults, exceptions
|
7
6
|
from runnable.datastore import BaseRunLogStore, RunLog
|
8
7
|
|
9
8
|
logger = logging.getLogger(defaults.LOGGER_NAME)
|
10
9
|
|
11
10
|
|
12
|
-
class
|
11
|
+
class AnyPathRunLogStore(BaseRunLogStore):
|
13
12
|
"""
|
14
13
|
In this type of Run Log store, we use a file system to store the JSON run log.
|
15
14
|
|
@@ -43,51 +42,11 @@ class FileSystemRunLogstore(BaseRunLogStore):
|
|
43
42
|
|
44
43
|
return summary
|
45
44
|
|
46
|
-
|
47
|
-
|
48
|
-
Write the run log to the folder
|
49
|
-
|
50
|
-
Args:
|
51
|
-
run_log (RunLog): The run log to be added to the database
|
52
|
-
"""
|
53
|
-
write_to = self.log_folder_name
|
54
|
-
utils.safe_make_dir(write_to)
|
55
|
-
|
56
|
-
write_to_path = Path(write_to)
|
57
|
-
run_id = run_log.run_id
|
58
|
-
json_file_path = write_to_path / f"{run_id}.json"
|
59
|
-
|
60
|
-
with json_file_path.open("w") as fw:
|
61
|
-
json.dump(run_log.model_dump(), fw, ensure_ascii=True, indent=4) # pylint: disable=no-member
|
62
|
-
|
63
|
-
def get_from_folder(self, run_id: str) -> RunLog:
|
64
|
-
"""
|
65
|
-
Look into the run log folder for the run log for the run id.
|
66
|
-
|
67
|
-
If the run log does not exist, raise an exception. If it does, decode it
|
68
|
-
as a RunLog and return it
|
45
|
+
@abstractmethod
|
46
|
+
def write_to_path(self, run_log: RunLog): ...
|
69
47
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
Raises:
|
74
|
-
FileNotFoundError: If the Run Log has not been found.
|
75
|
-
|
76
|
-
Returns:
|
77
|
-
RunLog: The decoded Run log
|
78
|
-
"""
|
79
|
-
write_to = self.log_folder_name
|
80
|
-
|
81
|
-
read_from_path = Path(write_to)
|
82
|
-
json_file_path = read_from_path / f"{run_id}.json"
|
83
|
-
|
84
|
-
if not json_file_path.exists():
|
85
|
-
raise FileNotFoundError(f"Expected {json_file_path} is not present")
|
86
|
-
|
87
|
-
with json_file_path.open("r") as fr:
|
88
|
-
json_str = json.load(fr)
|
89
|
-
run_log = RunLog(**json_str) # pylint: disable=no-member
|
90
|
-
return run_log
|
48
|
+
@abstractmethod
|
49
|
+
def read_from_path(self, run_id: str) -> RunLog: ...
|
91
50
|
|
92
51
|
def create_run_log(
|
93
52
|
self,
|
@@ -116,7 +75,7 @@ class FileSystemRunLogstore(BaseRunLogStore):
|
|
116
75
|
tag=tag,
|
117
76
|
status=status,
|
118
77
|
)
|
119
|
-
self.
|
78
|
+
self.write_to_path(run_log)
|
120
79
|
return run_log
|
121
80
|
|
122
81
|
def get_run_log_by_id(
|
@@ -130,7 +89,7 @@ class FileSystemRunLogstore(BaseRunLogStore):
|
|
130
89
|
"""
|
131
90
|
try:
|
132
91
|
logger.info(f"{self.service_name} Getting a Run Log for : {run_id}")
|
133
|
-
run_log = self.
|
92
|
+
run_log = self.read_from_path(run_id)
|
134
93
|
return run_log
|
135
94
|
except FileNotFoundError as e:
|
136
95
|
raise exceptions.RunLogNotFoundError(run_id) from e
|
@@ -142,4 +101,4 @@ class FileSystemRunLogstore(BaseRunLogStore):
|
|
142
101
|
logger.info(
|
143
102
|
f"{self.service_name} Putting the run log in the DB: {run_log.run_id}"
|
144
103
|
)
|
145
|
-
self.
|
104
|
+
self.write_to_path(run_log)
|
@@ -2,14 +2,16 @@ import json
|
|
2
2
|
import logging
|
3
3
|
from pathlib import Path
|
4
4
|
from string import Template
|
5
|
-
from typing import Any, Dict, Optional,
|
5
|
+
from typing import Any, Dict, Optional, Union
|
6
|
+
|
7
|
+
from cloudpathlib import CloudPath
|
6
8
|
|
7
9
|
from extensions.run_log_store.generic_chunked import ChunkedRunLogStore
|
8
10
|
from runnable import defaults, utils
|
9
11
|
|
10
12
|
logger = logging.getLogger(defaults.LOGGER_NAME)
|
11
13
|
|
12
|
-
|
14
|
+
MixT = Union[CloudPath, Path]
|
13
15
|
|
14
16
|
|
15
17
|
class ChunkedFileSystemRunLogStore(ChunkedRunLogStore):
|
@@ -28,7 +30,7 @@ class ChunkedFileSystemRunLogStore(ChunkedRunLogStore):
|
|
28
30
|
|
29
31
|
def get_matches(
|
30
32
|
self, run_id: str, name: str, multiple_allowed: bool = False
|
31
|
-
) -> Optional[Union[
|
33
|
+
) -> Optional[Union[list[Path], list[CloudPath], MixT]]:
|
32
34
|
"""
|
33
35
|
Get contents of files matching the pattern name*
|
34
36
|
|
@@ -78,7 +80,7 @@ class ChunkedFileSystemRunLogStore(ChunkedRunLogStore):
|
|
78
80
|
|
79
81
|
return str(name) + ".json"
|
80
82
|
|
81
|
-
def _store(self, run_id: str, contents: dict, name:
|
83
|
+
def _store(self, run_id: str, contents: dict, name: MixT, insert=False):
|
82
84
|
"""
|
83
85
|
Store the contents against the name in the folder.
|
84
86
|
|
@@ -87,15 +89,16 @@ class ChunkedFileSystemRunLogStore(ChunkedRunLogStore):
|
|
87
89
|
contents (dict): The dict to store
|
88
90
|
name (str): The name to store as
|
89
91
|
"""
|
92
|
+
log_folder_with_run_id = self.log_folder_with_run_id(run_id=run_id)
|
90
93
|
if insert:
|
91
|
-
name =
|
94
|
+
name = log_folder_with_run_id / name
|
92
95
|
|
93
|
-
utils.safe_make_dir(
|
96
|
+
utils.safe_make_dir(log_folder_with_run_id)
|
94
97
|
|
95
|
-
with open(self.safe_suffix_json(name), "w") as fw:
|
98
|
+
with open(log_folder_with_run_id / self.safe_suffix_json(name.name), "w") as fw:
|
96
99
|
json.dump(contents, fw, ensure_ascii=True, indent=4)
|
97
100
|
|
98
|
-
def _retrieve(self,
|
101
|
+
def _retrieve(self, run_id: str, name: MixT) -> dict:
|
99
102
|
"""
|
100
103
|
Does the job of retrieving from the folder.
|
101
104
|
|
@@ -106,8 +109,9 @@ class ChunkedFileSystemRunLogStore(ChunkedRunLogStore):
|
|
106
109
|
dict: The contents
|
107
110
|
"""
|
108
111
|
contents: dict = {}
|
112
|
+
log_folder_with_run_id = self.log_folder_with_run_id(run_id=run_id)
|
109
113
|
|
110
|
-
with open(self.safe_suffix_json(name), "r") as fr:
|
114
|
+
with open(log_folder_with_run_id / self.safe_suffix_json(name.name), "r") as fr:
|
111
115
|
contents = json.load(fr)
|
112
116
|
|
113
117
|
return contents
|