fractal-task-tools 0.0.2__tar.gz
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-0.0.2/LICENSE +29 -0
- fractal_task_tools-0.0.2/PKG-INFO +85 -0
- fractal_task_tools-0.0.2/README.md +65 -0
- fractal_task_tools-0.0.2/pyproject.toml +57 -0
- fractal_task_tools-0.0.2/setup.cfg +4 -0
- fractal_task_tools-0.0.2/src/fractal_task_tools/__init__.py +5 -0
- fractal_task_tools-0.0.2/src/fractal_task_tools/_args_schemas.py +214 -0
- fractal_task_tools-0.0.2/src/fractal_task_tools/_cli.py +72 -0
- fractal_task_tools-0.0.2/src/fractal_task_tools/_create_manifest.py +190 -0
- fractal_task_tools-0.0.2/src/fractal_task_tools/_descriptions.py +236 -0
- fractal_task_tools-0.0.2/src/fractal_task_tools/_package_name_tools.py +27 -0
- fractal_task_tools-0.0.2/src/fractal_task_tools/_pydantic_generatejsonschema.py +81 -0
- fractal_task_tools-0.0.2/src/fractal_task_tools/_signature_constraints.py +101 -0
- fractal_task_tools-0.0.2/src/fractal_task_tools/_task_docs.py +109 -0
- fractal_task_tools-0.0.2/src/fractal_task_tools/_titles.py +100 -0
- fractal_task_tools-0.0.2/src/fractal_task_tools/task_models.py +94 -0
- fractal_task_tools-0.0.2/src/fractal_task_tools.egg-info/PKG-INFO +85 -0
- fractal_task_tools-0.0.2/src/fractal_task_tools.egg-info/SOURCES.txt +23 -0
- fractal_task_tools-0.0.2/src/fractal_task_tools.egg-info/dependency_links.txt +1 -0
- fractal_task_tools-0.0.2/src/fractal_task_tools.egg-info/entry_points.txt +2 -0
- fractal_task_tools-0.0.2/src/fractal_task_tools.egg-info/requires.txt +8 -0
- fractal_task_tools-0.0.2/src/fractal_task_tools.egg-info/top_level.txt +1 -0
- fractal_task_tools-0.0.2/tests/test_create_schema_for_single_task.py +202 -0
- fractal_task_tools-0.0.2/tests/test_extract_function.py +26 -0
- fractal_task_tools-0.0.2/tests/test_unit_lib_descriptions.py +28 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright 2024 (C) Friedrich Miescher Institute for Biomedical Research and University of Zurich
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
|
8
|
+
|
|
9
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
10
|
+
list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
|
14
|
+
and/or other materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
17
|
+
contributors may be used to endorse or promote products derived from
|
|
18
|
+
this software without specific prior written permission.
|
|
19
|
+
|
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
24
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
25
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
26
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
27
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
28
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: fractal-task-tools
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: Shared tools for Fractal tasks
|
|
5
|
+
Author-email: Tommaso Comparin <tommaso.comparin@exact-lab.it>
|
|
6
|
+
License: BSD-3-Clause
|
|
7
|
+
Project-URL: homepage, https://github.com/fractal-analytics-platform/fractal-task-tools
|
|
8
|
+
Project-URL: repository, https://github.com/fractal-analytics-platform/fractal-task-tools
|
|
9
|
+
Project-URL: changelog, https://github.com/fractal-analytics-platform/fractal-task-tools/blob/main/CHANGELOG.md
|
|
10
|
+
Requires-Python: <3.13,>=3.10
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: pydantic<=2.8.2,>=2.0.0
|
|
14
|
+
Requires-Dist: docstring-parser==0.15
|
|
15
|
+
Provides-Extra: dev
|
|
16
|
+
Requires-Dist: bumpver==2024.1130; extra == "dev"
|
|
17
|
+
Requires-Dist: devtools==0.12.2; extra == "dev"
|
|
18
|
+
Requires-Dist: pytest<9.0.0,>=8.3.0; extra == "dev"
|
|
19
|
+
Requires-Dist: coverage<7.7.0,>=7.6.0; extra == "dev"
|
|
20
|
+
|
|
21
|
+
# Fractal task tools
|
|
22
|
+
|
|
23
|
+
[](https://pypi.org/project/fractal-task-tools/)
|
|
24
|
+
[](https://opensource.org/licenses/BSD-3-Clause)
|
|
25
|
+
[](https://github.com/fractal-analytics-platform/fractal-task-tools/actions/workflows/ci_pip.yml)
|
|
26
|
+
[](https://htmlpreview.github.io/?https://github.com/fractal-analytics-platform/fractal-task-tools/blob/python-coverage-comment-action-data/htmlcov/index.html)
|
|
27
|
+
|
|
28
|
+
Fractal-task-tools provides some basic tools for building tasks for the [Fractal](https://fractal-analytics-platform.github.io/) framework.
|
|
29
|
+
|
|
30
|
+

|
|
31
|
+
|
|
32
|
+
[Fractal](https://fractal-analytics-platform.github.io/) is a framework developed at the [BioVisionCenter](https://www.biovisioncenter.uzh.ch/en.html) to process bioimaging data at scale in the OME-Zarr format and prepare the images for interactive visualization.
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
# Get started
|
|
36
|
+
```console
|
|
37
|
+
$ python -m venv venv
|
|
38
|
+
|
|
39
|
+
$ source venv/bin/activate
|
|
40
|
+
|
|
41
|
+
$ python -m pip install -e .
|
|
42
|
+
[...]
|
|
43
|
+
Successfully installed annotated-types-0.7.0 docstring-parser-0.15 fractal-task-tools-0.0.1 pydantic-2.8.2 pydantic-core-2.20.1 typing-extensions-4.12.2
|
|
44
|
+
|
|
45
|
+
$ fractal-manifest create --help
|
|
46
|
+
usage: fractal-manifest create [-h] --package PACKAGE [--task-list-path TASK_LIST_PATH]
|
|
47
|
+
|
|
48
|
+
Create new manifest file
|
|
49
|
+
|
|
50
|
+
options:
|
|
51
|
+
-h, --help show this help message and exit
|
|
52
|
+
--package PACKAGE Example: 'fractal_tasks_core'
|
|
53
|
+
--task-list-path TASK_LIST_PATH
|
|
54
|
+
Dot-separated path to the `task_list.py` module, relative to the package root (default value:
|
|
55
|
+
'dev.task_list').
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
# Development
|
|
60
|
+
|
|
61
|
+
```console
|
|
62
|
+
$ python -m venv venv
|
|
63
|
+
|
|
64
|
+
$ source venv/bin/activate
|
|
65
|
+
|
|
66
|
+
$ python -m pip install -e .[dev]
|
|
67
|
+
[...]
|
|
68
|
+
Successfully installed asttokens-2.4.1 bumpver-2024.1130 click-8.1.8 colorama-0.4.6 coverage-7.6.12 devtools-0.12.2 exceptiongroup-1.2.2 executing-2.2.0 fractal-task-tools-0.0.1 iniconfig-2.0.0 lexid-2021.1006 packaging-24.2 pluggy-1.5.0 pygments-2.19.1 pytest-8.3.5 six-1.17.0 toml-0.10.2 tomli-2.2.1
|
|
69
|
+
|
|
70
|
+
$ pre-commit install
|
|
71
|
+
pre-commit installed at .git/hooks/pre-commit
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## How to make a release
|
|
75
|
+
From the development environment:
|
|
76
|
+
```
|
|
77
|
+
bumpver update --patch --dry
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
## Contributors and license
|
|
82
|
+
|
|
83
|
+
Fractal was conceived in the Liberali Lab at the Friedrich Miescher Institute for Biomedical Research and in the Pelkmans Lab at the University of Zurich by [@jluethi](https://github.com/jluethi) and [@gusqgm](https://github.com/gusqgm). The Fractal project is now developed at the [BioVisionCenter](https://www.biovisioncenter.uzh.ch/en.html) at the University of Zurich and the project lead is with [@jluethi](https://github.com/jluethi). The core development is done under contract by [eXact lab S.r.l.](https://www.exact-lab.it).
|
|
84
|
+
|
|
85
|
+
Unless otherwise specified, Fractal components are released under the BSD 3-Clause License, and copyright is with the BioVisionCenter at the University of Zurich.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Fractal task tools
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/fractal-task-tools/)
|
|
4
|
+
[](https://opensource.org/licenses/BSD-3-Clause)
|
|
5
|
+
[](https://github.com/fractal-analytics-platform/fractal-task-tools/actions/workflows/ci_pip.yml)
|
|
6
|
+
[](https://htmlpreview.github.io/?https://github.com/fractal-analytics-platform/fractal-task-tools/blob/python-coverage-comment-action-data/htmlcov/index.html)
|
|
7
|
+
|
|
8
|
+
Fractal-task-tools provides some basic tools for building tasks for the [Fractal](https://fractal-analytics-platform.github.io/) framework.
|
|
9
|
+
|
|
10
|
+

|
|
11
|
+
|
|
12
|
+
[Fractal](https://fractal-analytics-platform.github.io/) is a framework developed at the [BioVisionCenter](https://www.biovisioncenter.uzh.ch/en.html) to process bioimaging data at scale in the OME-Zarr format and prepare the images for interactive visualization.
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# Get started
|
|
16
|
+
```console
|
|
17
|
+
$ python -m venv venv
|
|
18
|
+
|
|
19
|
+
$ source venv/bin/activate
|
|
20
|
+
|
|
21
|
+
$ python -m pip install -e .
|
|
22
|
+
[...]
|
|
23
|
+
Successfully installed annotated-types-0.7.0 docstring-parser-0.15 fractal-task-tools-0.0.1 pydantic-2.8.2 pydantic-core-2.20.1 typing-extensions-4.12.2
|
|
24
|
+
|
|
25
|
+
$ fractal-manifest create --help
|
|
26
|
+
usage: fractal-manifest create [-h] --package PACKAGE [--task-list-path TASK_LIST_PATH]
|
|
27
|
+
|
|
28
|
+
Create new manifest file
|
|
29
|
+
|
|
30
|
+
options:
|
|
31
|
+
-h, --help show this help message and exit
|
|
32
|
+
--package PACKAGE Example: 'fractal_tasks_core'
|
|
33
|
+
--task-list-path TASK_LIST_PATH
|
|
34
|
+
Dot-separated path to the `task_list.py` module, relative to the package root (default value:
|
|
35
|
+
'dev.task_list').
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
# Development
|
|
40
|
+
|
|
41
|
+
```console
|
|
42
|
+
$ python -m venv venv
|
|
43
|
+
|
|
44
|
+
$ source venv/bin/activate
|
|
45
|
+
|
|
46
|
+
$ python -m pip install -e .[dev]
|
|
47
|
+
[...]
|
|
48
|
+
Successfully installed asttokens-2.4.1 bumpver-2024.1130 click-8.1.8 colorama-0.4.6 coverage-7.6.12 devtools-0.12.2 exceptiongroup-1.2.2 executing-2.2.0 fractal-task-tools-0.0.1 iniconfig-2.0.0 lexid-2021.1006 packaging-24.2 pluggy-1.5.0 pygments-2.19.1 pytest-8.3.5 six-1.17.0 toml-0.10.2 tomli-2.2.1
|
|
49
|
+
|
|
50
|
+
$ pre-commit install
|
|
51
|
+
pre-commit installed at .git/hooks/pre-commit
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## How to make a release
|
|
55
|
+
From the development environment:
|
|
56
|
+
```
|
|
57
|
+
bumpver update --patch --dry
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
## Contributors and license
|
|
62
|
+
|
|
63
|
+
Fractal was conceived in the Liberali Lab at the Friedrich Miescher Institute for Biomedical Research and in the Pelkmans Lab at the University of Zurich by [@jluethi](https://github.com/jluethi) and [@gusqgm](https://github.com/gusqgm). The Fractal project is now developed at the [BioVisionCenter](https://www.biovisioncenter.uzh.ch/en.html) at the University of Zurich and the project lead is with [@jluethi](https://github.com/jluethi). The core development is done under contract by [eXact lab S.r.l.](https://www.exact-lab.it).
|
|
64
|
+
|
|
65
|
+
Unless otherwise specified, Fractal components are released under the BSD 3-Clause License, and copyright is with the BioVisionCenter at the University of Zurich.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "fractal-task-tools"
|
|
3
|
+
version = "0.0.2"
|
|
4
|
+
description = "Shared tools for Fractal tasks"
|
|
5
|
+
authors = [
|
|
6
|
+
{name="Tommaso Comparin", email="tommaso.comparin@exact-lab.it"},
|
|
7
|
+
]
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
license = {text ="BSD-3-Clause"}
|
|
10
|
+
requires-python = ">=3.10,<3.13"
|
|
11
|
+
dependencies = [
|
|
12
|
+
"pydantic >=2.0.0,<=2.8.2",
|
|
13
|
+
"docstring-parser ==0.15",
|
|
14
|
+
]
|
|
15
|
+
[project.optional-dependencies]
|
|
16
|
+
dev = [
|
|
17
|
+
"bumpver ==2024.1130",
|
|
18
|
+
"devtools ==0.12.2",
|
|
19
|
+
"pytest >=8.3.0, <9.0.0",
|
|
20
|
+
"coverage >=7.6.0,<7.7.0",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
[project.urls]
|
|
24
|
+
homepage = "https://github.com/fractal-analytics-platform/fractal-task-tools"
|
|
25
|
+
repository = "https://github.com/fractal-analytics-platform/fractal-task-tools"
|
|
26
|
+
changelog = "https://github.com/fractal-analytics-platform/fractal-task-tools/blob/main/CHANGELOG.md"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
[build-system]
|
|
30
|
+
requires = ["setuptools >= 61.0"]
|
|
31
|
+
build-backend = "setuptools.build_meta"
|
|
32
|
+
|
|
33
|
+
[project.scripts]
|
|
34
|
+
fractal-manifest = "fractal_task_tools._cli:main"
|
|
35
|
+
|
|
36
|
+
[tool.bumpver]
|
|
37
|
+
current_version = "0.0.2"
|
|
38
|
+
version_pattern = "MAJOR.MINOR.PATCH[PYTAGNUM]"
|
|
39
|
+
commit_message = "bump version {old_version} -> {new_version}"
|
|
40
|
+
commit = true
|
|
41
|
+
tag = true
|
|
42
|
+
push = true
|
|
43
|
+
|
|
44
|
+
[tool.bumpver.file_patterns]
|
|
45
|
+
"pyproject.toml" = ['version = "{version}"$']
|
|
46
|
+
"src/fractal_task_tools/__init__.py" = ['__VERSION__ = "{version}"$']
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
[tool.coverage.run]
|
|
50
|
+
branch = true
|
|
51
|
+
parallel = true
|
|
52
|
+
relative_files = true
|
|
53
|
+
source = ["src"]
|
|
54
|
+
omit = ["tests/*", "*/.venv/*"]
|
|
55
|
+
|
|
56
|
+
[tool.coverage.report]
|
|
57
|
+
omit = ["tests/*", "*/.venv/*"]
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import os
|
|
3
|
+
from collections import Counter
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Any
|
|
6
|
+
from typing import Callable
|
|
7
|
+
from typing import Optional
|
|
8
|
+
|
|
9
|
+
from docstring_parser import parse as docparse
|
|
10
|
+
from pydantic._internal import _generate_schema
|
|
11
|
+
from pydantic._internal import _typing_extra
|
|
12
|
+
from pydantic._internal._config import ConfigWrapper
|
|
13
|
+
|
|
14
|
+
from ._descriptions import _get_class_attrs_descriptions
|
|
15
|
+
from ._descriptions import _get_function_args_descriptions
|
|
16
|
+
from ._descriptions import _insert_class_attrs_descriptions
|
|
17
|
+
from ._descriptions import _insert_function_args_descriptions
|
|
18
|
+
from ._pydantic_generatejsonschema import CustomGenerateJsonSchema
|
|
19
|
+
from ._signature_constraints import _extract_function
|
|
20
|
+
from ._signature_constraints import _validate_function_signature
|
|
21
|
+
from ._titles import _include_titles
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
_Schema = dict[str, Any]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _remove_attributes_from_descriptions(old_schema: _Schema) -> _Schema:
|
|
28
|
+
"""
|
|
29
|
+
Keeps only the description part of the docstrings: e.g from
|
|
30
|
+
```
|
|
31
|
+
'Custom class for Omero-channel window, based on OME-NGFF v0.4.\\n'
|
|
32
|
+
'\\n'
|
|
33
|
+
'Attributes:\\n'
|
|
34
|
+
'min: Do not change. It will be set to `0` by default.\\n'
|
|
35
|
+
'max: Do not change. It will be set according to bitdepth of the images\\n'
|
|
36
|
+
' by default (e.g. 65535 for 16 bit images).\\n'
|
|
37
|
+
'start: Lower-bound rescaling value for visualization.\\n'
|
|
38
|
+
'end: Upper-bound rescaling value for visualization.'
|
|
39
|
+
```
|
|
40
|
+
to `'Custom class for Omero-channel window, based on OME-NGFF v0.4.\\n'`.
|
|
41
|
+
|
|
42
|
+
Args:
|
|
43
|
+
old_schema: TBD
|
|
44
|
+
"""
|
|
45
|
+
new_schema = old_schema.copy()
|
|
46
|
+
if "$defs" in new_schema:
|
|
47
|
+
for name, definition in new_schema["$defs"].items():
|
|
48
|
+
if "description" in definition.keys():
|
|
49
|
+
parsed_docstring = docparse(definition["description"])
|
|
50
|
+
new_schema["$defs"][name][
|
|
51
|
+
"description"
|
|
52
|
+
] = parsed_docstring.short_description
|
|
53
|
+
elif "title" in definition.keys():
|
|
54
|
+
title = definition["title"]
|
|
55
|
+
new_schema["$defs"][name][
|
|
56
|
+
"description"
|
|
57
|
+
] = f"Missing description for {title}."
|
|
58
|
+
else:
|
|
59
|
+
new_schema["$defs"][name][
|
|
60
|
+
"description"
|
|
61
|
+
] = "Missing description"
|
|
62
|
+
logging.info("[_remove_attributes_from_descriptions] END")
|
|
63
|
+
return new_schema
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _create_schema_for_function(function: Callable) -> _Schema:
|
|
67
|
+
namespace = _typing_extra.add_module_globals(function, None)
|
|
68
|
+
gen_core_schema = _generate_schema.GenerateSchema(
|
|
69
|
+
ConfigWrapper(None), namespace
|
|
70
|
+
)
|
|
71
|
+
core_schema = gen_core_schema.generate_schema(function)
|
|
72
|
+
clean_core_schema = gen_core_schema.clean_schema(core_schema)
|
|
73
|
+
gen_json_schema = CustomGenerateJsonSchema()
|
|
74
|
+
json_schema = gen_json_schema.generate(
|
|
75
|
+
clean_core_schema, mode="validation"
|
|
76
|
+
)
|
|
77
|
+
return json_schema
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def create_schema_for_single_task(
|
|
81
|
+
executable: str,
|
|
82
|
+
package: Optional[str] = None,
|
|
83
|
+
pydantic_models: Optional[list[tuple[str, str, str]]] = None,
|
|
84
|
+
task_function: Optional[Callable] = None,
|
|
85
|
+
verbose: bool = False,
|
|
86
|
+
) -> _Schema:
|
|
87
|
+
"""
|
|
88
|
+
Main function to create a JSON Schema of task arguments
|
|
89
|
+
|
|
90
|
+
This function can be used in two ways:
|
|
91
|
+
|
|
92
|
+
1. `task_function` argument is `None`, `package` is set, and `executable`
|
|
93
|
+
is a path relative to that package.
|
|
94
|
+
2. `task_function` argument is provided, `executable` is an absolute path
|
|
95
|
+
to the function module, and `package` is `None. This is useful for
|
|
96
|
+
testing.
|
|
97
|
+
"""
|
|
98
|
+
|
|
99
|
+
DEFINITIONS_KEY = "$defs"
|
|
100
|
+
|
|
101
|
+
logging.info("[create_schema_for_single_task] START")
|
|
102
|
+
if task_function is None:
|
|
103
|
+
usage = "1"
|
|
104
|
+
# Usage 1 (standard)
|
|
105
|
+
if package is None:
|
|
106
|
+
raise ValueError(
|
|
107
|
+
"Cannot call `create_schema_for_single_task with "
|
|
108
|
+
f"{task_function=} and {package=}. Exit."
|
|
109
|
+
)
|
|
110
|
+
if os.path.isabs(executable):
|
|
111
|
+
raise ValueError(
|
|
112
|
+
"Cannot call `create_schema_for_single_task with "
|
|
113
|
+
f"{task_function=} and absolute {executable=}. Exit."
|
|
114
|
+
)
|
|
115
|
+
else:
|
|
116
|
+
usage = "2"
|
|
117
|
+
# Usage 2 (testing)
|
|
118
|
+
if package is not None:
|
|
119
|
+
raise ValueError(
|
|
120
|
+
"Cannot call `create_schema_for_single_task with "
|
|
121
|
+
f"{task_function=} and non-None {package=}. Exit."
|
|
122
|
+
)
|
|
123
|
+
if not os.path.isabs(executable):
|
|
124
|
+
raise ValueError(
|
|
125
|
+
"Cannot call `create_schema_for_single_task with "
|
|
126
|
+
f"{task_function=} and non-absolute {executable=}. Exit."
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
# Extract function from module
|
|
130
|
+
if usage == "1":
|
|
131
|
+
# Extract the function name (for the moment we assume the function has
|
|
132
|
+
# the same name as the module)
|
|
133
|
+
function_name = Path(executable).with_suffix("").name
|
|
134
|
+
# Extract the function object
|
|
135
|
+
task_function = _extract_function(
|
|
136
|
+
package_name=package,
|
|
137
|
+
module_relative_path=executable,
|
|
138
|
+
function_name=function_name,
|
|
139
|
+
verbose=verbose,
|
|
140
|
+
)
|
|
141
|
+
else:
|
|
142
|
+
# The function object is already available, extract its name
|
|
143
|
+
function_name = task_function.__name__
|
|
144
|
+
|
|
145
|
+
if verbose:
|
|
146
|
+
logging.info(f"[create_schema_for_single_task] {function_name=}")
|
|
147
|
+
logging.info(f"[create_schema_for_single_task] {task_function=}")
|
|
148
|
+
|
|
149
|
+
# Validate function signature against some custom constraints
|
|
150
|
+
_validate_function_signature(task_function)
|
|
151
|
+
|
|
152
|
+
# Create and clean up schema
|
|
153
|
+
schema = _create_schema_for_function(task_function)
|
|
154
|
+
schema = _remove_attributes_from_descriptions(schema)
|
|
155
|
+
|
|
156
|
+
# Include titles for custom-model-typed arguments
|
|
157
|
+
schema = _include_titles(
|
|
158
|
+
schema, definitions_key=DEFINITIONS_KEY, verbose=verbose
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
# Include main title
|
|
162
|
+
if schema.get("title") is None:
|
|
163
|
+
|
|
164
|
+
def to_camel_case(snake_str):
|
|
165
|
+
return "".join(
|
|
166
|
+
x.capitalize() for x in snake_str.lower().split("_")
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
schema["title"] = to_camel_case(task_function.__name__)
|
|
170
|
+
|
|
171
|
+
# Include descriptions of function. Note: this function works both
|
|
172
|
+
# for usages 1 or 2 (see docstring).
|
|
173
|
+
function_args_descriptions = _get_function_args_descriptions(
|
|
174
|
+
package_name=package,
|
|
175
|
+
module_path=executable,
|
|
176
|
+
function_name=function_name,
|
|
177
|
+
verbose=verbose,
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
schema = _insert_function_args_descriptions(
|
|
181
|
+
schema=schema, descriptions=function_args_descriptions
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
if pydantic_models is not None:
|
|
185
|
+
# Check that model names are unique
|
|
186
|
+
pydantic_models_names = [item[2] for item in pydantic_models]
|
|
187
|
+
duplicate_class_names = [
|
|
188
|
+
name
|
|
189
|
+
for name, count in Counter(pydantic_models_names).items()
|
|
190
|
+
if count > 1
|
|
191
|
+
]
|
|
192
|
+
if duplicate_class_names:
|
|
193
|
+
pydantic_models_str = " " + "\n ".join(map(str, pydantic_models))
|
|
194
|
+
raise ValueError(
|
|
195
|
+
"Cannot parse docstrings for models with non-unique names "
|
|
196
|
+
f"{duplicate_class_names}, in\n{pydantic_models_str}"
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
# Extract model-attribute descriptions and insert them into schema
|
|
200
|
+
for package_name, module_relative_path, class_name in pydantic_models:
|
|
201
|
+
attrs_descriptions = _get_class_attrs_descriptions(
|
|
202
|
+
package_name=package_name,
|
|
203
|
+
module_relative_path=module_relative_path,
|
|
204
|
+
class_name=class_name,
|
|
205
|
+
)
|
|
206
|
+
schema = _insert_class_attrs_descriptions(
|
|
207
|
+
schema=schema,
|
|
208
|
+
class_name=class_name,
|
|
209
|
+
descriptions=attrs_descriptions,
|
|
210
|
+
definition_key=DEFINITIONS_KEY,
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
logging.info("[create_schema_for_single_task] END")
|
|
214
|
+
return schema
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import argparse as ap
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
from fractal_task_tools._create_manifest import check_manifest_unchanged
|
|
5
|
+
from fractal_task_tools._create_manifest import create_manifest
|
|
6
|
+
from fractal_task_tools._create_manifest import write_manifest_to_file
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
main_parser = ap.ArgumentParser(
|
|
10
|
+
description="`fractal-manifest` command-line interface",
|
|
11
|
+
allow_abbrev=False,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
subparsers = main_parser.add_subparsers(
|
|
15
|
+
title="Available commands",
|
|
16
|
+
dest="cmd",
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
create_manifest_parser = subparsers.add_parser(
|
|
21
|
+
"create",
|
|
22
|
+
description="Create new manifest file",
|
|
23
|
+
allow_abbrev=False,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
check_manifest_parser = subparsers.add_parser(
|
|
27
|
+
"check",
|
|
28
|
+
description="Check existing manifest file",
|
|
29
|
+
allow_abbrev=False,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
for subparser in (create_manifest_parser, check_manifest_parser):
|
|
34
|
+
subparser.add_argument(
|
|
35
|
+
"--package",
|
|
36
|
+
type=str,
|
|
37
|
+
help="Example: 'fractal_tasks_core'",
|
|
38
|
+
required=True,
|
|
39
|
+
)
|
|
40
|
+
subparser.add_argument(
|
|
41
|
+
"--task-list-path",
|
|
42
|
+
type=str,
|
|
43
|
+
help=(
|
|
44
|
+
"Dot-separated path to the `task_list.py` module, "
|
|
45
|
+
"relative to the package root (default value: 'dev.task_list')."
|
|
46
|
+
),
|
|
47
|
+
default="dev.task_list",
|
|
48
|
+
required=False,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def main():
|
|
53
|
+
args = main_parser.parse_args(sys.argv[1:])
|
|
54
|
+
if args.cmd == "create":
|
|
55
|
+
manifest = create_manifest(
|
|
56
|
+
raw_package_name=args.package,
|
|
57
|
+
task_list_path=args.task_list_path,
|
|
58
|
+
)
|
|
59
|
+
write_manifest_to_file(
|
|
60
|
+
raw_package_name=args.package,
|
|
61
|
+
manifest=manifest,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
elif args.cmd == "check":
|
|
65
|
+
manifest = create_manifest(
|
|
66
|
+
raw_package_name=args.package,
|
|
67
|
+
task_list_path=args.task_list_path,
|
|
68
|
+
)
|
|
69
|
+
check_manifest_unchanged(
|
|
70
|
+
raw_package_name=args.package,
|
|
71
|
+
manifest=manifest,
|
|
72
|
+
)
|