fractal-task-tools 0.0.2__py3-none-any.whl → 0.0.4__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 fractal-task-tools might be problematic. Click here for more details.
- fractal_task_tools/__init__.py +1 -1
- fractal_task_tools/_cli.py +2 -2
- fractal_task_tools/_create_manifest.py +33 -9
- fractal_task_tools/_signature_constraints.py +2 -3
- fractal_task_tools/task_wrapper.py +73 -0
- {fractal_task_tools-0.0.2.dist-info → fractal_task_tools-0.0.4.dist-info}/METADATA +1 -1
- fractal_task_tools-0.0.4.dist-info/RECORD +18 -0
- fractal_task_tools-0.0.2.dist-info/RECORD +0 -17
- {fractal_task_tools-0.0.2.dist-info → fractal_task_tools-0.0.4.dist-info}/LICENSE +0 -0
- {fractal_task_tools-0.0.2.dist-info → fractal_task_tools-0.0.4.dist-info}/WHEEL +0 -0
- {fractal_task_tools-0.0.2.dist-info → fractal_task_tools-0.0.4.dist-info}/entry_points.txt +0 -0
- {fractal_task_tools-0.0.2.dist-info → fractal_task_tools-0.0.4.dist-info}/top_level.txt +0 -0
fractal_task_tools/__init__.py
CHANGED
fractal_task_tools/_cli.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import argparse as ap
|
|
2
2
|
import sys
|
|
3
3
|
|
|
4
|
-
from fractal_task_tools._create_manifest import
|
|
4
|
+
from fractal_task_tools._create_manifest import check_manifest
|
|
5
5
|
from fractal_task_tools._create_manifest import create_manifest
|
|
6
6
|
from fractal_task_tools._create_manifest import write_manifest_to_file
|
|
7
7
|
|
|
@@ -66,7 +66,7 @@ def main():
|
|
|
66
66
|
raw_package_name=args.package,
|
|
67
67
|
task_list_path=args.task_list_path,
|
|
68
68
|
)
|
|
69
|
-
|
|
69
|
+
check_manifest(
|
|
70
70
|
raw_package_name=args.package,
|
|
71
71
|
manifest=manifest,
|
|
72
72
|
)
|
|
@@ -3,6 +3,8 @@ Generate JSON schemas for task arguments and combine them into a manifest.
|
|
|
3
3
|
"""
|
|
4
4
|
import json
|
|
5
5
|
import logging
|
|
6
|
+
import os
|
|
7
|
+
import sys
|
|
6
8
|
from importlib import import_module
|
|
7
9
|
from pathlib import Path
|
|
8
10
|
from typing import Any
|
|
@@ -157,17 +159,26 @@ def write_manifest_to_file(
|
|
|
157
159
|
raw_package_name:
|
|
158
160
|
manifest: The manifest object
|
|
159
161
|
"""
|
|
162
|
+
logging.info("[write_manifest_to_file] START")
|
|
163
|
+
|
|
160
164
|
package_name = normalize_package_name(raw_package_name)
|
|
165
|
+
logging.info(f"[write_manifest_to_file] {package_name=}")
|
|
166
|
+
|
|
161
167
|
imported_package = import_module(package_name)
|
|
162
168
|
package_root_dir = Path(imported_package.__file__).parent
|
|
163
|
-
manifest_path = package_root_dir / MANIFEST_FILENAME
|
|
164
|
-
|
|
169
|
+
manifest_path = (package_root_dir / MANIFEST_FILENAME).as_posix()
|
|
170
|
+
logging.info(f"[write_manifest_to_file] {os.getcwd()=}")
|
|
171
|
+
logging.info(f"[write_manifest_to_file] {package_root_dir=}")
|
|
172
|
+
logging.info(f"[write_manifest_to_file] {manifest_path=}")
|
|
173
|
+
|
|
174
|
+
with open(manifest_path, "w") as f:
|
|
165
175
|
json.dump(manifest, f, indent=2)
|
|
166
176
|
f.write("\n")
|
|
167
|
-
|
|
177
|
+
|
|
178
|
+
logging.info("[write_manifest_to_file] END")
|
|
168
179
|
|
|
169
180
|
|
|
170
|
-
def
|
|
181
|
+
def check_manifest(
|
|
171
182
|
*,
|
|
172
183
|
raw_package_name: str,
|
|
173
184
|
manifest: str,
|
|
@@ -179,12 +190,25 @@ def check_manifest_unchanged(
|
|
|
179
190
|
raw_package_name:
|
|
180
191
|
manifest: The manifest object
|
|
181
192
|
"""
|
|
193
|
+
|
|
182
194
|
package_name = normalize_package_name(raw_package_name)
|
|
195
|
+
logging.info(f"[check_manifest] {package_name=}")
|
|
196
|
+
|
|
183
197
|
imported_package = import_module(package_name)
|
|
184
198
|
package_root_dir = Path(imported_package.__file__).parent
|
|
185
|
-
manifest_path = package_root_dir / MANIFEST_FILENAME
|
|
186
|
-
|
|
199
|
+
manifest_path = (package_root_dir / MANIFEST_FILENAME).as_posix()
|
|
200
|
+
logging.info(f"[check_manifest] {os.getcwd()=}")
|
|
201
|
+
logging.info(f"[check_manifest] {package_root_dir=}")
|
|
202
|
+
logging.info(f"[check_manifest] {manifest_path=}")
|
|
203
|
+
|
|
204
|
+
with open(manifest_path, "r") as f:
|
|
187
205
|
old_manifest = json.load(f)
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
206
|
+
if manifest == old_manifest:
|
|
207
|
+
logging.info("[check_manifest] On-disk manifest is up to date.")
|
|
208
|
+
else:
|
|
209
|
+
logging.error("[check_manifest] On-disk manifest is not up to date.")
|
|
210
|
+
print(json.dumps(old_manifest, indent=2))
|
|
211
|
+
print(json.dumps(manifest, indent=2))
|
|
212
|
+
sys.exit("New/old manifests differ")
|
|
213
|
+
|
|
214
|
+
logging.info("[check_manifest] END")
|
|
@@ -3,7 +3,6 @@ import logging
|
|
|
3
3
|
from importlib import import_module
|
|
4
4
|
from inspect import signature
|
|
5
5
|
from pathlib import Path
|
|
6
|
-
from typing import Callable
|
|
7
6
|
|
|
8
7
|
from pydantic.v1.decorator import ALT_V_ARGS
|
|
9
8
|
from pydantic.v1.decorator import ALT_V_KWARGS
|
|
@@ -25,7 +24,7 @@ def _extract_function(
|
|
|
25
24
|
function_name: str,
|
|
26
25
|
package_name: str,
|
|
27
26
|
verbose: bool = False,
|
|
28
|
-
) ->
|
|
27
|
+
) -> callable:
|
|
29
28
|
"""
|
|
30
29
|
Extract function from a module with the same name.
|
|
31
30
|
|
|
@@ -58,7 +57,7 @@ def _extract_function(
|
|
|
58
57
|
return task_function
|
|
59
58
|
|
|
60
59
|
|
|
61
|
-
def _validate_function_signature(function:
|
|
60
|
+
def _validate_function_signature(function: callable):
|
|
62
61
|
"""
|
|
63
62
|
Validate the function signature.
|
|
64
63
|
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Standard input/output interface for tasks.
|
|
3
|
+
"""
|
|
4
|
+
import json
|
|
5
|
+
import logging
|
|
6
|
+
from argparse import ArgumentParser
|
|
7
|
+
from json import JSONEncoder
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Optional
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class TaskParameterEncoder(JSONEncoder):
|
|
13
|
+
"""
|
|
14
|
+
Custom JSONEncoder that transforms Path objects to strings.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
def default(self, value):
|
|
18
|
+
"""
|
|
19
|
+
Subclass implementation of `default`, to serialize Path objects as
|
|
20
|
+
strings.
|
|
21
|
+
"""
|
|
22
|
+
if isinstance(value, Path):
|
|
23
|
+
return value.as_posix()
|
|
24
|
+
return JSONEncoder.default(self, value)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def run_fractal_task(
|
|
28
|
+
*,
|
|
29
|
+
task_function: callable,
|
|
30
|
+
logger_name: Optional[str] = None,
|
|
31
|
+
):
|
|
32
|
+
"""
|
|
33
|
+
Implement standard task interface and call task_function.
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
task_function: the callable function that runs the task.
|
|
37
|
+
logger_name: TBD
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
# Parse `-j` and `--metadata-out` arguments
|
|
41
|
+
parser = ArgumentParser()
|
|
42
|
+
parser.add_argument(
|
|
43
|
+
"--args-json", help="Read parameters from json file", required=True
|
|
44
|
+
)
|
|
45
|
+
parser.add_argument(
|
|
46
|
+
"--out-json",
|
|
47
|
+
help="Output file to redirect serialised returned data",
|
|
48
|
+
required=True,
|
|
49
|
+
)
|
|
50
|
+
parsed_args = parser.parse_args()
|
|
51
|
+
|
|
52
|
+
# Set logger
|
|
53
|
+
logger = logging.getLogger(logger_name)
|
|
54
|
+
|
|
55
|
+
# Preliminary check
|
|
56
|
+
if Path(parsed_args.out_json).exists():
|
|
57
|
+
logger.error(
|
|
58
|
+
f"Output file {parsed_args.out_json} already exists. Terminating"
|
|
59
|
+
)
|
|
60
|
+
exit(1)
|
|
61
|
+
|
|
62
|
+
# Read parameters dictionary
|
|
63
|
+
with open(parsed_args.args_json, "r") as f:
|
|
64
|
+
pars = json.load(f)
|
|
65
|
+
|
|
66
|
+
# Run task
|
|
67
|
+
logger.info(f"START {task_function.__name__} task")
|
|
68
|
+
metadata_update = task_function(**pars)
|
|
69
|
+
logger.info(f"END {task_function.__name__} task")
|
|
70
|
+
|
|
71
|
+
# Write output metadata to file, with custom JSON encoder
|
|
72
|
+
with open(parsed_args.out_json, "w") as fout:
|
|
73
|
+
json.dump(metadata_update, fout, cls=TaskParameterEncoder, indent=2)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
fractal_task_tools/__init__.py,sha256=uWJsphgKkHSVpBiZcVd3e8XP9NZ9RA5QAbsJOjThLJ8,79
|
|
2
|
+
fractal_task_tools/_args_schemas.py,sha256=Ka5IAAEdC7xg03ZHMl5jFbv4Sk8JR1QKbxFl7soevlQ,7829
|
|
3
|
+
fractal_task_tools/_cli.py,sha256=6x2wWG6cFTw0m8HsxLmeboT3AMNf7ofhAI2kWEZMkx8,1849
|
|
4
|
+
fractal_task_tools/_create_manifest.py,sha256=DTl1gV4XvQy_ArOAOSUzKLcTHYuE_un94dBvpfdkeeI,6922
|
|
5
|
+
fractal_task_tools/_descriptions.py,sha256=n7WcoIBQ4FEd16BI26iL-Sh6bEQ76jlU32JfJBF4U0A,7566
|
|
6
|
+
fractal_task_tools/_package_name_tools.py,sha256=_UT2cThh742V6M0XT9m0_aByhj5fXRSjATKt_MIXFVg,819
|
|
7
|
+
fractal_task_tools/_pydantic_generatejsonschema.py,sha256=qZuID7YUXOdAcL8OqsWjNFNumOIAgdJillc1lA2cHIY,3136
|
|
8
|
+
fractal_task_tools/_signature_constraints.py,sha256=RzJwoL-NMD0HXEACR4_4aD8OOc59lxqEreT7oTc6xJo,3188
|
|
9
|
+
fractal_task_tools/_task_docs.py,sha256=aEXozSKf3a7weOwJMHyTVJTvHlCKgDr1qoU-AAO3bZI,3401
|
|
10
|
+
fractal_task_tools/_titles.py,sha256=GLWn-06fgQD6qzOM75H59EV0MMCXc8jVpHqGanYzNbw,3000
|
|
11
|
+
fractal_task_tools/task_models.py,sha256=xTbdk3lf6T70o8idEWw-bdjA2dDz0KDIrBjdoh_A9Lc,2243
|
|
12
|
+
fractal_task_tools/task_wrapper.py,sha256=IO2wyD1ph23V_xPNGnjtXewuJ4TOGzq3U4KBlEzB4to,1959
|
|
13
|
+
fractal_task_tools-0.0.4.dist-info/LICENSE,sha256=1SGAsQ3Jm_nIU7c2TgtTZe_IOKjm9BDsrcf2r98xrdk,1584
|
|
14
|
+
fractal_task_tools-0.0.4.dist-info/METADATA,sha256=6jYc6G00qJU60AFxYD9kxkBLWpCsDWB03JNvcFeVJGE,4212
|
|
15
|
+
fractal_task_tools-0.0.4.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
|
|
16
|
+
fractal_task_tools-0.0.4.dist-info/entry_points.txt,sha256=zE4qv7QhuiqN6DaPkmJV18X1xyYoUi0HIJ-uAg2M6TU,66
|
|
17
|
+
fractal_task_tools-0.0.4.dist-info/top_level.txt,sha256=2VBpiMDIBMJGOEPiHHX3njYEZGLhr4L0nu8vfkcNVzw,19
|
|
18
|
+
fractal_task_tools-0.0.4.dist-info/RECORD,,
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
fractal_task_tools/__init__.py,sha256=MRGHqa12kl23-BtFENLSAtLR5nzimughL2HEce80xc0,79
|
|
2
|
-
fractal_task_tools/_args_schemas.py,sha256=Ka5IAAEdC7xg03ZHMl5jFbv4Sk8JR1QKbxFl7soevlQ,7829
|
|
3
|
-
fractal_task_tools/_cli.py,sha256=ikEwNVhzvr_X5PY5_s02lH7JvRcuHgjFs-hoIFQjXYo,1869
|
|
4
|
-
fractal_task_tools/_create_manifest.py,sha256=Ses8N5RliTtbvaHGJwTjuE2sGyBCoJUJtcyO7JPX23w,6147
|
|
5
|
-
fractal_task_tools/_descriptions.py,sha256=n7WcoIBQ4FEd16BI26iL-Sh6bEQ76jlU32JfJBF4U0A,7566
|
|
6
|
-
fractal_task_tools/_package_name_tools.py,sha256=_UT2cThh742V6M0XT9m0_aByhj5fXRSjATKt_MIXFVg,819
|
|
7
|
-
fractal_task_tools/_pydantic_generatejsonschema.py,sha256=qZuID7YUXOdAcL8OqsWjNFNumOIAgdJillc1lA2cHIY,3136
|
|
8
|
-
fractal_task_tools/_signature_constraints.py,sha256=1ixh8acxwY5_jRdyn7KfyRDDuwqQQ2R6Zf1xlElheWY,3216
|
|
9
|
-
fractal_task_tools/_task_docs.py,sha256=aEXozSKf3a7weOwJMHyTVJTvHlCKgDr1qoU-AAO3bZI,3401
|
|
10
|
-
fractal_task_tools/_titles.py,sha256=GLWn-06fgQD6qzOM75H59EV0MMCXc8jVpHqGanYzNbw,3000
|
|
11
|
-
fractal_task_tools/task_models.py,sha256=xTbdk3lf6T70o8idEWw-bdjA2dDz0KDIrBjdoh_A9Lc,2243
|
|
12
|
-
fractal_task_tools-0.0.2.dist-info/LICENSE,sha256=1SGAsQ3Jm_nIU7c2TgtTZe_IOKjm9BDsrcf2r98xrdk,1584
|
|
13
|
-
fractal_task_tools-0.0.2.dist-info/METADATA,sha256=07uk2zPoBCvv5Nv9Sb_k2jNsBw_2xYb-09XUwouo8Ps,4212
|
|
14
|
-
fractal_task_tools-0.0.2.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
|
|
15
|
-
fractal_task_tools-0.0.2.dist-info/entry_points.txt,sha256=zE4qv7QhuiqN6DaPkmJV18X1xyYoUi0HIJ-uAg2M6TU,66
|
|
16
|
-
fractal_task_tools-0.0.2.dist-info/top_level.txt,sha256=2VBpiMDIBMJGOEPiHHX3njYEZGLhr4L0nu8vfkcNVzw,19
|
|
17
|
-
fractal_task_tools-0.0.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|