Skip to content

Commit 0a12704

Browse files
committed
Support reading docs_info from file
1 parent 62ad0d5 commit 0a12704

File tree

3 files changed

+52
-6
lines changed

3 files changed

+52
-6
lines changed

fractal_tasks_core/dev/create_manifest.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
create_schema_for_single_task,
2323
)
2424
from fractal_tasks_core.dev.lib_task_docs import create_docs_info
25+
from fractal_tasks_core.dev.lib_task_docs import read_docs_info_from_file
2526

2627

2728
logging.basicConfig(level=logging.INFO)
@@ -126,11 +127,19 @@ def create_manifest(
126127
task_dict[f"args_schema_{kind}"] = schema
127128

128129
# Update docs_info, based on task-function description
129-
docs_info = create_docs_info(
130-
executable_non_parallel=task_obj.executable_non_parallel,
131-
executable_parallel=task_obj.executable_parallel,
132-
package=package,
133-
)
130+
docs_info = task_dict.get("docs_info")
131+
if docs_info is None:
132+
docs_info = create_docs_info(
133+
executable_non_parallel=task_obj.executable_non_parallel,
134+
executable_parallel=task_obj.executable_parallel,
135+
package=package,
136+
)
137+
elif docs_info.startswith("file:"):
138+
docs_info = read_docs_info_from_file(
139+
docs_info=docs_info,
140+
task_list_path=task_list_module.__file__,
141+
)
142+
134143
if docs_info is not None:
135144
task_dict["docs_info"] = docs_info
136145
if docs_link is not None:

fractal_tasks_core/dev/lib_task_docs.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def create_docs_info(
5757
executable_non_parallel: Optional[str] = None,
5858
executable_parallel: Optional[str] = None,
5959
package: str = "fractal_tasks_core",
60-
) -> list[str]:
60+
) -> str:
6161
"""
6262
Return task description based on function docstring.
6363
"""
@@ -81,3 +81,39 @@ def create_docs_info(
8181
docs_info = "".join(docs_info)
8282
logging.info("[create_docs_info] END")
8383
return docs_info
84+
85+
86+
def read_docs_info_from_file(
87+
*,
88+
docs_info: str,
89+
task_list_path: str,
90+
) -> str:
91+
"""
92+
Return task description based on the content of a file.
93+
94+
An example of valid argument is
95+
```
96+
docs_info = "file:relative/path/info.md"
97+
```
98+
where the path is relative to the folder where `task_list.py` is.
99+
"""
100+
logging.info("[read_docs_info_from_file] START")
101+
print(docs_info)
102+
print(task_list_path)
103+
104+
if not docs_info.startswith("file:"):
105+
raise ValueError(f"Invalid docs_info='{docs_info}'.")
106+
relative_path = Path(docs_info[5:])
107+
if relative_path.is_absolute():
108+
raise ValueError(
109+
f"Invalid docs_info='{docs_info}' (path must be relative)."
110+
)
111+
base_path = Path(task_list_path).parent
112+
113+
docs_path = (base_path / relative_path).as_posix()
114+
115+
logging.info(f"[read_docs_info_from_file] Reading docs from {docs_path}")
116+
with open(docs_path, "r") as f:
117+
docs_info = f.read()
118+
logging.info("[read_docs_info_from_file] END")
119+
return docs_info

fractal_tasks_core/dev/task_models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class Config:
3535
category: Optional[str] = None
3636
modality: Optional[str] = None
3737
tags: list[str] = Field(default_factory=list)
38+
docs_info: Optional[str] = None
3839

3940

4041
class CompoundTask(_BaseTask):

0 commit comments

Comments
 (0)