Skip to content

Commit 7379d13

Browse files
committed
Make output comply with task-group endpoint
1 parent 5f6720d commit 7379d13

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

tasks/data_retrieval/create_tasks_data.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from pathlib import Path
33
import requests
44
import json
5-
from os import environ
65
from zipfile import ZipFile
76
from typing import Any
87
from pydantic import BaseModel
@@ -36,6 +35,12 @@ class Config:
3635
extra = "forbid"
3736

3837

38+
class TaskGroupReadV2(BaseModel):
39+
pkg_name: str
40+
version: Optional[str] = None
41+
task_list: list[TaskReadV2]
42+
43+
3944
def parse_wheel_filename(wheel_path: str) -> dict[str, str]:
4045
"""
4146
Given a wheel-file name or path, extract distribution and version.
@@ -210,12 +215,12 @@ def _get_task_type(
210215
if not (source.startswith("#") or source == "")
211216
]
212217

213-
TASKS = []
218+
TASK_GROUPS = []
214219
for source in sources:
215220
t_start = time.perf_counter()
216221
print(f"START processing {source=}")
217222
try:
218-
new_tasks = []
223+
task_list = []
219224
data = get_package_info(source)
220225
pkg_name = data["name"]
221226
pkg_version = data.get("version")
@@ -229,16 +234,26 @@ def _get_task_type(
229234
new_task["version"] = pkg_version
230235
new_task["type"] = _get_task_type(task)
231236
TaskReadV2(**new_task)
232-
new_tasks.append(new_task)
237+
task_list.append(new_task)
238+
239+
task_group = dict(
240+
pkg_name=pkg_name,
241+
version=pkg_version,
242+
task_list=task_list,
243+
)
233244
except Exception as e:
234245
print(f"ERROR, skip.\nOriginal error:\n{str(e)}")
235-
TASKS.extend(new_tasks)
246+
247+
TaskGroupReadV2(**task_group)
248+
249+
TASK_GROUPS.append(task_group)
250+
236251
t_end = time.perf_counter()
237252
print(f"END processing {source=} - elapsed {t_end-t_start:.3f} s.")
238253
print()
239254

240255
output_file = Path(__file__).parent / "tasks_data.json"
241256
with output_file.open("w") as f:
242-
json.dump(TASKS, f, indent=2)
257+
json.dump(TASK_GROUPS, f, indent=2)
243258

244259
DOWNLOAD_FOLDER.rmdir()

0 commit comments

Comments
 (0)