fractal-task-tools 0.0.3__py3-none-any.whl → 0.0.5__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/task_models.py +2 -3
- fractal_task_tools/task_wrapper.py +71 -0
- {fractal_task_tools-0.0.3.dist-info → fractal_task_tools-0.0.5.dist-info}/METADATA +1 -1
- {fractal_task_tools-0.0.3.dist-info → fractal_task_tools-0.0.5.dist-info}/RECORD +9 -8
- {fractal_task_tools-0.0.3.dist-info → fractal_task_tools-0.0.5.dist-info}/LICENSE +0 -0
- {fractal_task_tools-0.0.3.dist-info → fractal_task_tools-0.0.5.dist-info}/WHEEL +0 -0
- {fractal_task_tools-0.0.3.dist-info → fractal_task_tools-0.0.5.dist-info}/entry_points.txt +0 -0
- {fractal_task_tools-0.0.3.dist-info → fractal_task_tools-0.0.5.dist-info}/top_level.txt +0 -0
fractal_task_tools/__init__.py
CHANGED
|
@@ -2,13 +2,12 @@ from typing import Any
|
|
|
2
2
|
from typing import Optional
|
|
3
3
|
|
|
4
4
|
from pydantic import BaseModel
|
|
5
|
+
from pydantic import ConfigDict
|
|
5
6
|
from pydantic import Field
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
class _BaseTask(BaseModel):
|
|
9
|
-
|
|
10
|
-
arbitrary_types_allowed = True
|
|
11
|
-
extra = "forbid"
|
|
10
|
+
model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True)
|
|
12
11
|
|
|
13
12
|
name: str
|
|
14
13
|
executable: str
|
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
Ref https://docs.python.org/3/library/json.html
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
def default(self, obj):
|
|
20
|
+
if isinstance(obj, Path):
|
|
21
|
+
return obj.as_posix()
|
|
22
|
+
return super().default(obj)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def run_fractal_task(
|
|
26
|
+
*,
|
|
27
|
+
task_function: callable,
|
|
28
|
+
logger_name: Optional[str] = None,
|
|
29
|
+
):
|
|
30
|
+
"""
|
|
31
|
+
Implement standard task interface and call task_function.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
task_function: the callable function that runs the task.
|
|
35
|
+
logger_name: TBD
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
# Parse `-j` and `--metadata-out` arguments
|
|
39
|
+
parser = ArgumentParser()
|
|
40
|
+
parser.add_argument(
|
|
41
|
+
"--args-json", help="Read parameters from json file", required=True
|
|
42
|
+
)
|
|
43
|
+
parser.add_argument(
|
|
44
|
+
"--out-json",
|
|
45
|
+
help="Output file to redirect serialised returned data",
|
|
46
|
+
required=True,
|
|
47
|
+
)
|
|
48
|
+
parsed_args = parser.parse_args()
|
|
49
|
+
|
|
50
|
+
# Set logger
|
|
51
|
+
logger = logging.getLogger(logger_name)
|
|
52
|
+
|
|
53
|
+
# Preliminary check
|
|
54
|
+
if Path(parsed_args.out_json).exists():
|
|
55
|
+
logger.error(
|
|
56
|
+
f"Output file {parsed_args.out_json} already exists. Terminating"
|
|
57
|
+
)
|
|
58
|
+
exit(1)
|
|
59
|
+
|
|
60
|
+
# Read parameters dictionary
|
|
61
|
+
with open(parsed_args.args_json, "r") as f:
|
|
62
|
+
pars = json.load(f)
|
|
63
|
+
|
|
64
|
+
# Run task
|
|
65
|
+
logger.info(f"START {task_function.__name__} task")
|
|
66
|
+
metadata_update = task_function(**pars)
|
|
67
|
+
logger.info(f"END {task_function.__name__} task")
|
|
68
|
+
|
|
69
|
+
# Write output metadata to file, with custom JSON encoder
|
|
70
|
+
with open(parsed_args.out_json, "w") as fout:
|
|
71
|
+
json.dump(metadata_update, fout, cls=TaskParameterEncoder, indent=2)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
fractal_task_tools/__init__.py,sha256=
|
|
1
|
+
fractal_task_tools/__init__.py,sha256=MnFTaW45JfhnCV-zkWHY7mQ_mXPAF8ISIYUTznGWs2M,79
|
|
2
2
|
fractal_task_tools/_args_schemas.py,sha256=Ka5IAAEdC7xg03ZHMl5jFbv4Sk8JR1QKbxFl7soevlQ,7829
|
|
3
3
|
fractal_task_tools/_cli.py,sha256=6x2wWG6cFTw0m8HsxLmeboT3AMNf7ofhAI2kWEZMkx8,1849
|
|
4
4
|
fractal_task_tools/_create_manifest.py,sha256=DTl1gV4XvQy_ArOAOSUzKLcTHYuE_un94dBvpfdkeeI,6922
|
|
@@ -8,10 +8,11 @@ fractal_task_tools/_pydantic_generatejsonschema.py,sha256=qZuID7YUXOdAcL8OqsWjNF
|
|
|
8
8
|
fractal_task_tools/_signature_constraints.py,sha256=RzJwoL-NMD0HXEACR4_4aD8OOc59lxqEreT7oTc6xJo,3188
|
|
9
9
|
fractal_task_tools/_task_docs.py,sha256=aEXozSKf3a7weOwJMHyTVJTvHlCKgDr1qoU-AAO3bZI,3401
|
|
10
10
|
fractal_task_tools/_titles.py,sha256=GLWn-06fgQD6qzOM75H59EV0MMCXc8jVpHqGanYzNbw,3000
|
|
11
|
-
fractal_task_tools/task_models.py,sha256=
|
|
12
|
-
fractal_task_tools
|
|
13
|
-
fractal_task_tools-0.0.
|
|
14
|
-
fractal_task_tools-0.0.
|
|
15
|
-
fractal_task_tools-0.0.
|
|
16
|
-
fractal_task_tools-0.0.
|
|
17
|
-
fractal_task_tools-0.0.
|
|
11
|
+
fractal_task_tools/task_models.py,sha256=kgvEv5NQD8e8I9tyaFrnvxUxbKm6vH63r-cnID1jHE8,2269
|
|
12
|
+
fractal_task_tools/task_wrapper.py,sha256=dhphKgxDm4EUxZnsrAy20hJPD6bGdqx7tNg9N_QzlCo,1878
|
|
13
|
+
fractal_task_tools-0.0.5.dist-info/LICENSE,sha256=1SGAsQ3Jm_nIU7c2TgtTZe_IOKjm9BDsrcf2r98xrdk,1584
|
|
14
|
+
fractal_task_tools-0.0.5.dist-info/METADATA,sha256=rlEyaK2tRYJxgoVaFyCdAbs0TNhk3t2s6c75z9Utj0o,4212
|
|
15
|
+
fractal_task_tools-0.0.5.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
|
|
16
|
+
fractal_task_tools-0.0.5.dist-info/entry_points.txt,sha256=zE4qv7QhuiqN6DaPkmJV18X1xyYoUi0HIJ-uAg2M6TU,66
|
|
17
|
+
fractal_task_tools-0.0.5.dist-info/top_level.txt,sha256=2VBpiMDIBMJGOEPiHHX3njYEZGLhr4L0nu8vfkcNVzw,19
|
|
18
|
+
fractal_task_tools-0.0.5.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|