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 77f04f9 commit 06d62b6
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 36 deletions.
12 changes: 9 additions & 3 deletions fractal_client/cmd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,9 @@ 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 @@ -320,7 +322,9 @@ 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 @@ -372,7 +376,9 @@ def user(client: AuthClient, subcmd: str, batch: bool = False, **kwargs) -> Inte
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
12 changes: 9 additions & 3 deletions fractal_client/cmd/_task_collection.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import json
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 Down Expand Up @@ -47,7 +47,11 @@ def task_collect_pip(
if wheel_path is None:
with open(wheel_path, "rb") as wheel_buffer:
file = {
"file": (Path(wheel_path).name, wheel_buffer.read(), "application/zip")
"file": (
Path(wheel_path).name,
wheel_buffer.read(),
"application/zip",
)
}
res = client.post(
f"{settings.BASE_URL}/task/collect/pip/{is_private}",
Expand Down Expand Up @@ -107,7 +111,9 @@ def task_collect_custom(
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
100 changes: 75 additions & 25 deletions fractal_client/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
Institute for Biomedical Research and Pelkmans Lab from the University of
Zurich.
"""

import argparse as ap


Expand Down Expand Up @@ -80,7 +79,9 @@
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 @@ -127,7 +128,9 @@
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 @@ -197,7 +200,9 @@
# 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 Down Expand Up @@ -254,7 +259,9 @@
)
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 @@ -313,7 +320,9 @@
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 @@ -369,12 +378,15 @@
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 @@ -456,7 +468,9 @@
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 @@ -465,7 +479,9 @@
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 @@ -483,7 +499,10 @@
)
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 @@ -493,7 +512,9 @@
"--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 @@ -515,7 +536,9 @@
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 @@ -556,7 +579,9 @@
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 @@ -655,7 +680,9 @@
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 @@ -689,14 +716,20 @@
"--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 @@ -747,8 +780,12 @@
),
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 @@ -806,8 +843,12 @@
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 @@ -864,7 +905,9 @@
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 @@ -903,7 +946,9 @@
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 @@ -912,7 +957,10 @@
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 @@ -945,7 +993,9 @@
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
22 changes: 17 additions & 5 deletions tests/test_task_collection.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import json
import logging
import sys
import time
from urllib.request import urlopen
from urllib.request import urlretrieve
import logging

import pytest
from devtools import debug

Expand Down Expand Up @@ -52,7 +53,13 @@ def test_task_collection_invalid_pinned_dependency(invoke, caplog):
"""
PACKAGE = "devtools"
with pytest.raises(SystemExit):
invoke(("task collect " f"{PACKAGE} " "--pinned-dependency invalid-string"))
invoke(
(
"task collect "
f"{PACKAGE} "
"--pinned-dependency invalid-string"
)
)
# Check that payload was prepared correctly
log_lines = [record.message for record in caplog.records]
debug(log_lines)
Expand Down Expand Up @@ -84,15 +91,18 @@ def test_task_collection(invoke_as_custom_user, user_factory, new_name):
initial_task_list = len(res.data)

res0 = invoke_as_custom_user(
f"task collect --private {PACKAGE_PATH} --wheel-path {PACKAGE_PATH}", **new_user
f"task collect --private {PACKAGE_PATH} --wheel-path {PACKAGE_PATH}",
**new_user,
)
debug(res0.data)
activity_id = res0.data["id"]

# Wait until collection is complete
starting_time = time.perf_counter()
while True:
res1 = invoke_as_custom_user(f"task check-collection {activity_id}", **new_user)
res1 = invoke_as_custom_user(
f"task check-collection {activity_id}", **new_user
)
assert res1.retcode == 0
time.sleep(0.1)
if res1.data["status"] == "OK":
Expand All @@ -101,7 +111,9 @@ def test_task_collection(invoke_as_custom_user, user_factory, new_name):
assert time.perf_counter() - starting_time < COLLECTION_TIMEOUT

# Check successful status and no logs
res2 = invoke_as_custom_user(f"task check-collection {activity_id}", **new_user)
res2 = invoke_as_custom_user(
f"task check-collection {activity_id}", **new_user
)
assert res2.retcode == 0
assert res2.data["status"] == "OK"
assert res2.data["log"] is None
Expand Down

0 comments on commit 06d62b6

Please sign in to comment.