55from zipfile import ZipFile
66from typing import Any
77from 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
1118DOWNLOAD_FOLDER = Path (__file__ ).parent / "downloads"
1421
1522class 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
123140def 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
166192def get_package_info (source : str ) -> dict [str , Any ]:
@@ -210,11 +236,7 @@ def _get_task_type(
210236sources_file = Path (__file__ ).parent / "sources.txt"
211237with 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
219241TASK_GROUPS = []
220242for 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
259288output_file = Path (__file__ ).parent / "tasks.json"
0 commit comments