Skip to content

utils_background

FUNCTION DESCRIPTION
prepare_tasks_metadata

Based on the package manifest and additional info, prepare the task list.

Classes

Functions:

prepare_tasks_metadata(*, package_manifest, package_root, python_command, package_version)

Based on the package manifest and additional info, prepare the task list.

PARAMETER DESCRIPTION

package_manifest

TYPE: ManifestV2

package_root

TYPE: Path

python_command

Command that runs Python, to be prepended to each task executable. It can be a path (e.g. /some/venv/bin/python) or a multi-word command (e.g. apptainer exec ... python).

TYPE: str

package_version

TYPE: str

Source code in fractal_server/tasks/v2/utils_background.py
def prepare_tasks_metadata(
    *,
    package_manifest: ManifestV2,
    package_root: Path,
    python_command: str,
    package_version: str,
) -> list[TaskCreate]:
    """
    Based on the package manifest and additional info, prepare the task list.

    Args:
        package_manifest:
        package_root:
        python_command: Command that runs Python, to be prepended to each
            task executable. It can be a path (e.g. `/some/venv/bin/python`)
            or a multi-word command (e.g. `apptainer exec ... python`).
        package_version:
    """

    task_list = []
    for _task in package_manifest.task_list:
        # Set non-command attributes
        task_attributes = {}
        task_attributes["version"] = package_version
        if package_manifest.has_args_schemas:
            task_attributes["args_schema_version"] = (
                package_manifest.args_schema_version
            )
        # Set command attributes
        if _task.executable_non_parallel is not None:
            non_parallel_path = package_root / _task.executable_non_parallel
            cmd_non_parallel = (
                f"{python_command} {non_parallel_path.as_posix()}"
            )
            task_attributes["command_non_parallel"] = cmd_non_parallel
        if _task.executable_parallel is not None:
            parallel_path = package_root / _task.executable_parallel
            cmd_parallel = f"{python_command} {parallel_path.as_posix()}"
            task_attributes["command_parallel"] = cmd_parallel
        # Create object
        task_obj = TaskCreate(
            **_task.model_dump(
                exclude={
                    "executable_non_parallel",
                    "executable_parallel",
                }
            ),
            **task_attributes,
            authors=package_manifest.authors,
        )
        task_list.append(task_obj)
    return task_list