Skip to content

Commit

Permalink
add wheel path in task collect cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
mfranzon committed Dec 4, 2024
1 parent 7442bdb commit 77f04f9
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 112 deletions.
15 changes: 4 additions & 11 deletions fractal_client/cmd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def project(
batch: bool = False,
**kwargs,
) -> Interface:

if subcmd == "new":
parameters = ["name"]
function_kwargs = get_kwargs(parameters, kwargs)
Expand Down Expand Up @@ -129,7 +128,6 @@ def task(
batch: bool = False,
**kwargs,
) -> Interface:

if subcmd == "list":
iface = get_task_list(client)
elif subcmd == "collect":
Expand All @@ -138,6 +136,7 @@ def task(
"package_version",
"python_version",
"package_extras",
"wheel_path",
"pinned_dependency",
"private",
]
Expand Down Expand Up @@ -308,9 +307,7 @@ def version(client: Client, **kwargs) -> Interface:
try:
res = client.get(f"{settings.FRACTAL_SERVER}/api/alive/")
data = res.json()
server_str = (
f"\turl: {settings.FRACTAL_SERVER}\tversion: {data['version']}"
)
server_str = f"\turl: {settings.FRACTAL_SERVER}\tversion: {data['version']}"
except ConnectError:
server_str = f"\tConnection to '{settings.FRACTAL_SERVER}' refused"

Expand All @@ -323,9 +320,7 @@ def version(client: Client, **kwargs) -> Interface:
)


def user(
client: AuthClient, subcmd: str, batch: bool = False, **kwargs
) -> Interface:
def user(client: AuthClient, subcmd: str, batch: bool = False, **kwargs) -> Interface:
if subcmd == "register":
parameters = [
"new_email",
Expand Down Expand Up @@ -377,9 +372,7 @@ def user(
return iface


def group(
client: AuthClient, subcmd: str, batch: bool = False, **kwargs
) -> Interface:
def group(client: AuthClient, subcmd: str, batch: bool = False, **kwargs) -> Interface:
if subcmd == "list":
parameters = ["user_ids"]
function_kwargs = get_kwargs(parameters, kwargs)
Expand Down
29 changes: 19 additions & 10 deletions fractal_client/cmd/_task_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import sys

from pathlib import Path
from fractal_client.authclient import AuthClient
from fractal_client.config import settings
from fractal_client.interface import Interface
Expand All @@ -15,11 +16,11 @@ def task_collect_pip(
package_version: str | None = None,
python_version: str | None = None,
package_extras: str | None = None,
wheel_path: str | None = None,
pinned_dependency: list[str] | None = None,
private: bool = False,
batch: bool = False,
) -> Interface:

# Construct TaskCollectPip object
task_collect = dict(package=package)
if package_version:
Expand All @@ -43,10 +44,21 @@ def task_collect_pip(

is_private = "?private=true" if private else ""

res = client.post(
f"{settings.BASE_URL}/task/collect/pip/{is_private}",
json=task_collect,
)
if wheel_path is None:
with open(wheel_path, "rb") as wheel_buffer:
file = {
"file": (Path(wheel_path).name, wheel_buffer.read(), "application/zip")
}
res = client.post(
f"{settings.BASE_URL}/task/collect/pip/{is_private}",
data=task_collect,
files=file,
)
else:
res = client.post(
f"{settings.BASE_URL}/task/collect/pip/{is_private}",
data=task_collect,
)

task_group_activity = check_response(res, expected_status_code=202)
if batch:
Expand All @@ -67,7 +79,6 @@ def task_collect_custom(
private: bool = False,
batch: bool = False,
) -> Interface:

try:
with open(manifest, "r") as f:
manifest_dict = json.load(f)
Expand All @@ -93,12 +104,10 @@ def task_collect_custom(

res = client.post(
f"{settings.BASE_URL}/task/collect/custom/{is_private}",
json=task_collect,
data=task_collect,
)

task_list = check_response(
res, expected_status_code=201, redact_long_payload=True
)
task_list = check_response(res, expected_status_code=201, redact_long_payload=True)

if batch:
task_ids = [str(task["id"]) for task in task_list]
Expand Down
103 changes: 28 additions & 75 deletions fractal_client/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
Institute for Biomedical Research and Pelkmans Lab from the University of
Zurich.
"""

import argparse as ap


Expand Down Expand Up @@ -79,9 +80,7 @@
description="Show details of single project.",
allow_abbrev=False,
)
project_show_parser.add_argument(
"project_id", type=int, help="ID of project to show."
)
project_show_parser.add_argument("project_id", type=int, help="ID of project to show.")

# project delete
project_delete_parser = project_subparsers.add_parser(
Expand Down Expand Up @@ -128,9 +127,7 @@
project_edit_parser.add_argument(
"project_id", type=int, help="ID of the project to edit."
)
project_edit_parser.add_argument(
"--new-name", help="New project name.", required=False
)
project_edit_parser.add_argument("--new-name", help="New project name.", required=False)


# DATASET GROUP
Expand Down Expand Up @@ -200,9 +197,7 @@
# task collect
task_collect_parser = task_subparsers.add_parser(
"collect",
description=(
"Install and collect all tasks from a pip-installable package."
),
description=("Install and collect all tasks from a pip-installable package."),
allow_abbrev=False,
)
task_collect_parser.add_argument(
Expand All @@ -226,6 +221,9 @@
"`fractal-tasks-core[torch,tensorflow]`."
),
)
task_collect_parser.add_argument(
"--wheel-path", help=("Path to python package wheel file")
)
task_collect_parser.add_argument(
"--pinned-dependency",
action="append",
Expand Down Expand Up @@ -256,9 +254,7 @@
)
task_collect_custom_parser.add_argument(
"python_interpreter",
help=(
"Absolute path to the Python interpreter to be used for running tasks."
),
help=("Absolute path to the Python interpreter to be used for running tasks."),
)
task_collect_custom_parser.add_argument(
"manifest", help="Local path of the Manifest of the Fractal task package."
Expand Down Expand Up @@ -317,9 +313,7 @@
argument_default=ap.SUPPRESS,
allow_abbrev=False,
)
task_new_parser.add_argument(
"name", help="A human readable name for the task."
)
task_new_parser.add_argument("name", help="A human readable name for the task.")
task_new_parser.add_argument(
"--command-non-parallel",
help="The non parallel command that executes the task.",
Expand Down Expand Up @@ -375,15 +369,12 @@
task_edit_id_or_name_group.add_argument(
"--id", help="ID of the task to edit.", type=int
)
task_edit_id_or_name_group.add_argument(
"--name", help="Name of the task to edit."
)
task_edit_id_or_name_group.add_argument("--name", help="Name of the task to edit.")

task_edit_parser.add_argument(
"--version",
help=(
"Version of the task to edit "
"(only accepted in combination with `--name`)."
"Version of the task to edit " "(only accepted in combination with `--name`)."
),
)
task_edit_parser.add_argument("--new-version", help="New task version.")
Expand Down Expand Up @@ -465,9 +456,7 @@
allow_abbrev=False,
)
workflow_delete_parser.add_argument("project_id", type=int, help="Project ID.")
workflow_delete_parser.add_argument(
"workflow_id", type=int, help="Workflow ID."
)
workflow_delete_parser.add_argument("workflow_id", type=int, help="Workflow ID.")


# workflow add task
Expand All @@ -476,9 +465,7 @@
description="Add new task to specific workflow.",
allow_abbrev=False,
)
workflow_add_task_parser.add_argument(
"project_id", type=int, help="Project ID."
)
workflow_add_task_parser.add_argument("project_id", type=int, help="Project ID.")
workflow_add_task_parser.add_argument(
"workflow_id",
type=int,
Expand All @@ -496,10 +483,7 @@
)
workflow_add_task_parser.add_argument(
"--task-version",
help=(
"Version of task to add "
"(only accepted in combination with --task-name)."
),
help=("Version of task to add " "(only accepted in combination with --task-name)."),
)
workflow_add_task_parser.add_argument(
"--order", help="Order of this task within the workflow's task list."
Expand All @@ -509,9 +493,7 @@
"--args-non-parallel", help="Args for non parallel tasks"
)

workflow_add_task_parser.add_argument(
"--args-parallel", help="Args for parallel tasks"
)
workflow_add_task_parser.add_argument("--args-parallel", help="Args for parallel tasks")

workflow_add_task_parser.add_argument(
"--meta-non-parallel", help="Metadata file fornon parallel tasks"
Expand All @@ -533,9 +515,7 @@
description="Edit task within specific workflow.",
allow_abbrev=False,
)
workflow_edit_task_parser.add_argument(
"project_id", type=int, help="Project ID."
)
workflow_edit_task_parser.add_argument("project_id", type=int, help="Project ID.")
workflow_edit_task_parser.add_argument(
"workflow_id",
type=int,
Expand Down Expand Up @@ -576,9 +556,7 @@
description="Remove task from a specific workflow.",
allow_abbrev=False,
)
workflow_remove_task_parser.add_argument(
"project_id", type=int, help="Project ID."
)
workflow_remove_task_parser.add_argument("project_id", type=int, help="Project ID.")
workflow_remove_task_parser.add_argument(
"workflow_id",
type=int,
Expand Down Expand Up @@ -677,9 +655,7 @@
description="Download full folder of workflow-execution job.",
allow_abbrev=False,
)
job_download_logs_parser.add_argument(
"project_id", type=int, help="Project ID."
)
job_download_logs_parser.add_argument("project_id", type=int, help="Project ID.")
job_download_logs_parser.add_argument("job_id", type=int, help="Job ID.")
job_download_logs_parser.add_argument(
"--output",
Expand Down Expand Up @@ -713,20 +689,14 @@
"--start",
dest="first_task_index",
type=int,
help=(
"Positional index of the first task to be executed"
" (starting from 0)."
),
help=("Positional index of the first task to be executed" " (starting from 0)."),
required=False,
)
job_submit_parser.add_argument(
"--end",
dest="last_task_index",
type=int,
help=(
"Positional index of the last task to be executed"
" (starting from 0)."
),
help=("Positional index of the last task to be executed" " (starting from 0)."),
required=False,
)
job_submit_parser.add_argument(
Expand Down Expand Up @@ -777,12 +747,8 @@
),
allow_abbrev=False,
)
user_register_parser.add_argument(
"new_email", help="Email to be used as username."
)
user_register_parser.add_argument(
"new_password", help="Password for the new user."
)
user_register_parser.add_argument("new_email", help="Email to be used as username.")
user_register_parser.add_argument("new_password", help="Password for the new user.")
user_register_parser.add_argument(
"--project-dir",
help="User-writeable base folder, used e.g. for default `zarr_dir` paths.",
Expand Down Expand Up @@ -840,12 +806,8 @@
allow_abbrev=False,
)
user_edit_parser.add_argument("user_id", help="ID of the user.", type=int)
user_edit_parser.add_argument(
"--new-email", help="New email address.", required=False
)
user_edit_parser.add_argument(
"--new-password", help="New password.", required=False
)
user_edit_parser.add_argument("--new-email", help="New email address.", required=False)
user_edit_parser.add_argument("--new-password", help="New password.", required=False)
user_edit_parser.add_argument(
"--new-username", help="New user username.", required=False
)
Expand Down Expand Up @@ -902,9 +864,7 @@
description=("Reset user-group membership for an existing user."),
allow_abbrev=False,
)
user_set_groups_parser.add_argument(
"user_id", help="ID of the user.", type=int
)
user_set_groups_parser.add_argument("user_id", help="ID of the user.", type=int)
user_set_groups_parser.add_argument(
"group_ids",
help=(
Expand Down Expand Up @@ -943,9 +903,7 @@
group_get_parser = group_subparsers.add_parser(
"get", description="Get single group.", allow_abbrev=False
)
group_get_parser.add_argument(
"group_id", help="ID of the group to get.", type=int
)
group_get_parser.add_argument("group_id", help="ID of the group to get.", type=int)

# group new
group_new_parser = group_subparsers.add_parser(
Expand All @@ -954,10 +912,7 @@
group_new_parser.add_argument("name", help="Name of the new group.", type=str)
group_new_parser.add_argument(
"--viewer-paths",
help=(
"List of group's `viewer_paths` (e.g "
"`--viewer-paths /something /else`)",
),
help=("List of group's `viewer_paths` (e.g " "`--viewer-paths /something /else`)",),
required=False,
type=str,
nargs="+",
Expand Down Expand Up @@ -990,9 +945,7 @@
group_add_user_parser.add_argument(
"group_id", help="ID of the group to which to add the user.", type=int
)
group_add_user_parser.add_argument(
"user_id", help="ID of the user to add.", type=int
)
group_add_user_parser.add_argument("user_id", help="ID of the user to add.", type=int)

# group remove-user
group_remove_user_parser = group_subparsers.add_parser(
Expand Down
Loading

0 comments on commit 77f04f9

Please sign in to comment.