Skip to content

Commit bab83db

Browse files
authored
Merge pull request #11 from fractal-analytics-platform/updates
Updates
2 parents f012f3d + 6c8ca95 commit bab83db

File tree

5 files changed

+121
-17
lines changed

5 files changed

+121
-17
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
_site/
2+
__pycache__
23
.sass-cache/
34
.jekyll-cache/
45
.jekyll-metadata

docs/fractal_tasks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ hide:
2020
}
2121
</style>
2222

23-
Here is a list of task packages which can be used in Fractal (note that not all existing packages are currently listed).
23+
Here is a list of task packages which can be used in Fractal. Note that not all existing packages are currently listed, see https://fractal-analytics-platform.github.io/fractal-tasks-core/all_tasks for a more complete list.
2424

2525
<iframe src="../task-table/" class="tasks-iframe">
2626
</iframe>

tasks_data_retrieval/create_tasks_data.py

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@
55
from zipfile import ZipFile
66
from typing import Any
77
from pydantic import BaseModel
8-
from typing import Optional, Literal
8+
from typing import Optional
9+
from typing import Literal
10+
11+
import sys
12+
13+
sys.path.append(Path(__file__).parent)
14+
from install_instructions import get_github_install_instructions
15+
from install_instructions import get_pypi_install_instructions
916

1017

1118
DOWNLOAD_FOLDER = Path(__file__).parent / "downloads"
@@ -14,7 +21,7 @@
1421

1522
class TaskReadV2(BaseModel):
1623
"""
17-
Based on
24+
Customization of
1825
https://github.com/fractal-analytics-platform/fractal-server/blob/main/fractal_server/app/schemas/v2/task.py
1926
"""
2027

@@ -30,6 +37,7 @@ class TaskReadV2(BaseModel):
3037
modality: Optional[str] = None
3138
authors: Optional[str] = None
3239
tags: list[str]
40+
install_instructions: Optional[str] = None
3341

3442
class Config:
3543
extra = "forbid"
@@ -117,7 +125,16 @@ def handle_pypi_project(pypi_project_url: str) -> dict[str, Any]:
117125
manifest = load_manifest_from_zip(wheel_path)
118126
Path(wheel_path).unlink()
119127

120-
return dict(manifest=manifest, **info)
128+
install_instructions = get_pypi_install_instructions(
129+
project_name=project_name,
130+
version=info["version"],
131+
)
132+
133+
return dict(
134+
manifest=manifest,
135+
install_instructions=install_instructions,
136+
**info,
137+
)
121138

122139

123140
def handle_github_repository(github_url: str) -> dict[str, Any]:
@@ -160,7 +177,16 @@ def handle_github_repository(github_url: str) -> dict[str, Any]:
160177
manifest = load_manifest_from_zip(wheel_path)
161178
Path(wheel_path).unlink()
162179

163-
return dict(manifest=manifest, **info)
180+
install_instructions = get_github_install_instructions(
181+
wheel_name=Path(wheel_path).name,
182+
wheel_url=wheel_asset_browser_download_url,
183+
)
184+
185+
return dict(
186+
manifest=manifest,
187+
install_instructions=install_instructions,
188+
**info,
189+
)
164190

165191

166192
def get_package_info(source: str) -> dict[str, Any]:
@@ -210,11 +236,7 @@ def _get_task_type(
210236
sources_file = Path(__file__).parent / "sources.txt"
211237
with sources_file.open("r") as f:
212238
sources = f.read().splitlines()
213-
sources = [
214-
source
215-
for source in sources
216-
if not (source.startswith("#") or source == "")
217-
]
239+
sources = [source for source in sources if not (source.startswith("#") or source == "")]
218240

219241
TASK_GROUPS = []
220242
for source in sources:
@@ -226,6 +248,7 @@ def _get_task_type(
226248
pkg_name = data["name"]
227249
pkg_version = data.get("version")
228250
authors = data["manifest"].get("authors")
251+
install_instructions = data.get("install_instructions")
229252
pkg_task_list = data["manifest"]["task_list"]
230253
for task in pkg_task_list:
231254
new_task = dict()
@@ -236,6 +259,7 @@ def _get_task_type(
236259
new_task["version"] = pkg_version
237260
new_task["type"] = _get_task_type(task)
238261
new_task["authors"] = authors
262+
new_task["install_instructions"] = install_instructions
239263
TaskReadV2(**new_task)
240264
task_list.append(new_task)
241265

@@ -253,7 +277,12 @@ def _get_task_type(
253277
TASK_GROUPS.append(task_group)
254278

255279
t_end = time.perf_counter()
256-
print(f"END processing {source=} - version={pkg_version}' - added {ntasks} tasks - elapsed {t_end-t_start:.3f} s.")
280+
print(
281+
f"END processing {source=} - "
282+
f"version={pkg_version}' - "
283+
f"added {ntasks} tasks - "
284+
f"elapsed {t_end-t_start:.3f} s."
285+
)
257286
print()
258287

259288
output_file = Path(__file__).parent / "tasks.json"
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
INSTALL_INSTRUCTIONS_TITLE_1 = "## How to add this task to a Fractal instance\n"
2+
INSTALL_INSTRUCTIONS_TITLE_2 = "## How to install this task in a Python environment\n"
3+
4+
5+
def _get_default_template_pypi() -> str:
6+
lines = [
7+
INSTALL_INSTRUCTIONS_TITLE_1,
8+
"Trigger a _PyPI_ task collection with package `__PROJECT_NAME__` and package version `__VERSION__`.",
9+
"",
10+
INSTALL_INSTRUCTIONS_TITLE_2,
11+
"```",
12+
'pip install "__PROJECT_NAME__==__VERSION__"',
13+
"```",
14+
]
15+
template = "\n".join(lines) + "\n"
16+
return template
17+
18+
19+
def _get_default_template_pypi_with_extra(extra: str) -> str:
20+
lines = [
21+
INSTALL_INSTRUCTIONS_TITLE_1,
22+
f"Trigger a _PyPI_ task collection for package `__PROJECT_NAME__`, package version `__VERSION__` and package extras {extra}.",
23+
"",
24+
INSTALL_INSTRUCTIONS_TITLE_2,
25+
"```",
26+
f'pip install "__PROJECT_NAME__[{extra}]==__VERSION__"',
27+
"```",
28+
]
29+
template = "\n".join(lines) + "\n"
30+
return template
31+
32+
33+
def _get_default_template_wheel_url() -> str:
34+
lines = [
35+
INSTALL_INSTRUCTIONS_TITLE_1,
36+
"1. Download the wheel file from [this link](__WHEEL_URL__),",
37+
"2. Trigger a _local_ task collection by uploading the wheel file.",
38+
"",
39+
INSTALL_INSTRUCTIONS_TITLE_2,
40+
"1. Download the wheel file from [this link](__WHEEL_URL__)",
41+
"2. `pip install __WHEEL_NAME__`",
42+
]
43+
template = "\n".join(lines) + "\n"
44+
return template
45+
46+
47+
def _get_default_template_wheel_url_with_extra(extra: str) -> str:
48+
lines = [
49+
INSTALL_INSTRUCTIONS_TITLE_1,
50+
"1. Download the wheel file from [this link](__WHEEL_URL__),",
51+
f"2. Trigger a _local_ task collection by uploading the wheel file, with package extras {extra}.",
52+
"",
53+
INSTALL_INSTRUCTIONS_TITLE_2,
54+
"1. Download the wheel file from [this link](__WHEEL_URL__)",
55+
f"2. `pip install \"__WHEEL_NAME__[{extra}]\"`",
56+
]
57+
template = "\n".join(lines) + "\n"
58+
return template
59+
60+
61+
def get_pypi_install_instructions(*, project_name: str, version: str) -> str:
62+
instructions = _get_default_template_pypi()
63+
if project_name == "fractal-tasks-core":
64+
instructions = _get_default_template_pypi_with_extra(extra="fractal-tasks")
65+
instructions = instructions.replace("__PROJECT_NAME__", project_name)
66+
instructions = instructions.replace("__VERSION__", version)
67+
print(instructions)
68+
return instructions
69+
70+
71+
def get_github_install_instructions(*, wheel_name: str, wheel_url: str) -> str:
72+
instructions = _get_default_template_wheel_url()
73+
if wheel_name.startswith("scmultiplex"):
74+
instructions = _get_default_template_wheel_url_with_extra(extra="fractal-tasks")
75+
instructions = instructions.replace("__WHEEL_NAME__", wheel_name)
76+
instructions = instructions.replace("__WHEEL_URL__", wheel_url)
77+
print(instructions)
78+
return instructions

tasks_data_retrieval/sources.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
https://pypi.org/project/fractal-tasks-core/
1+
https://pypi.org/project/fractal-tasks-core
22
https://pypi.org/project/fractal-faim-ipa
33
https://pypi.org/project/fractal-lif-converters
44
https://pypi.org/project/operetta-compose
55
https://github.com/fractal-analytics-platform/fractal-helper-tasks
66
https://github.com/fmi-basel/gliberal-scMultipleX
7-
8-
# https://github.com/Apricot-Therapeutics/APx_fractal_task_collection
9-
# https://github.com/fractal-analytics-platform/fractal-plantseg-tasks
10-
# https://github.com/m-albert/fractal-ome-zarr-hcs-stitching/archive
11-
# https://github.com/fractal-analytics-platform/fractal-ilastik-tasksC/archive/refs/tags/0.1.1.zip
7+
https://github.com/m-albert/fractal-ome-zarr-hcs-stitching

0 commit comments

Comments
 (0)