5
5
from zipfile import ZipFile
6
6
from typing import Any
7
7
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
9
16
10
17
11
18
DOWNLOAD_FOLDER = Path (__file__ ).parent / "downloads"
14
21
15
22
class TaskReadV2 (BaseModel ):
16
23
"""
17
- Based on
24
+ Customization of
18
25
https://github.com/fractal-analytics-platform/fractal-server/blob/main/fractal_server/app/schemas/v2/task.py
19
26
"""
20
27
@@ -30,6 +37,7 @@ class TaskReadV2(BaseModel):
30
37
modality : Optional [str ] = None
31
38
authors : Optional [str ] = None
32
39
tags : list [str ]
40
+ install_instructions : Optional [str ] = None
33
41
34
42
class Config :
35
43
extra = "forbid"
@@ -117,7 +125,16 @@ def handle_pypi_project(pypi_project_url: str) -> dict[str, Any]:
117
125
manifest = load_manifest_from_zip (wheel_path )
118
126
Path (wheel_path ).unlink ()
119
127
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
+ )
121
138
122
139
123
140
def handle_github_repository (github_url : str ) -> dict [str , Any ]:
@@ -160,7 +177,16 @@ def handle_github_repository(github_url: str) -> dict[str, Any]:
160
177
manifest = load_manifest_from_zip (wheel_path )
161
178
Path (wheel_path ).unlink ()
162
179
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
+ )
164
190
165
191
166
192
def get_package_info (source : str ) -> dict [str , Any ]:
@@ -210,11 +236,7 @@ def _get_task_type(
210
236
sources_file = Path (__file__ ).parent / "sources.txt"
211
237
with sources_file .open ("r" ) as f :
212
238
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 == "" )]
218
240
219
241
TASK_GROUPS = []
220
242
for source in sources :
@@ -226,6 +248,7 @@ def _get_task_type(
226
248
pkg_name = data ["name" ]
227
249
pkg_version = data .get ("version" )
228
250
authors = data ["manifest" ].get ("authors" )
251
+ install_instructions = data .get ("install_instructions" )
229
252
pkg_task_list = data ["manifest" ]["task_list" ]
230
253
for task in pkg_task_list :
231
254
new_task = dict ()
@@ -236,6 +259,7 @@ def _get_task_type(
236
259
new_task ["version" ] = pkg_version
237
260
new_task ["type" ] = _get_task_type (task )
238
261
new_task ["authors" ] = authors
262
+ new_task ["install_instructions" ] = install_instructions
239
263
TaskReadV2 (** new_task )
240
264
task_list .append (new_task )
241
265
@@ -253,7 +277,12 @@ def _get_task_type(
253
277
TASK_GROUPS .append (task_group )
254
278
255
279
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
+ )
257
286
print ()
258
287
259
288
output_file = Path (__file__ ).parent / "tasks.json"
0 commit comments