Skip to content

Commit

Permalink
Merge pull request #631 from fractal-analytics-platform/dev-v2-cli
Browse files Browse the repository at this point in the history
Dev v2 cli
  • Loading branch information
tcompa authored Apr 8, 2024
2 parents 60799b6 + e8d4cb8 commit a4ab987
Show file tree
Hide file tree
Showing 22 changed files with 786 additions and 1,996 deletions.
8 changes: 4 additions & 4 deletions fractal_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from .authclient import AuthClient
from .authclient import AuthenticationError
from .config import settings
from .interface import PrintInterface
from .interface import Interface
from .parser import parser_main


Expand Down Expand Up @@ -112,9 +112,9 @@ def handle(cli_args: List[str] = argv):
with AuthClient(username=username, password=password) as client:
interface = handler(client, **kwargs)
except AuthenticationError as e:
return PrintInterface(retcode=1, data=e.args[0])
return Interface(retcode=1, data=e.args[0])
except ConnectError as e:
return PrintInterface(
return Interface(
retcode=1,
data=(
f"ConnectError at {e.request.url}\n"
Expand All @@ -123,7 +123,7 @@ def handle(cli_args: List[str] = argv):
),
)
except Exception as e:
return PrintInterface(retcode=1, data=str(e))
return Interface(retcode=1, data=str(e))

return interface

Expand Down
103 changes: 33 additions & 70 deletions fractal_client/cmd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@

from ..authclient import AuthClient
from ..config import settings
from ..interface import BaseInterface
from ..interface import PrintInterface
from ..interface import Interface
from ._dataset import delete_dataset
from ._dataset import delete_resource
from ._dataset import get_dataset
from ._dataset import get_dataset_history
from ._dataset import get_dataset_status
from ._dataset import patch_dataset
from ._dataset import post_dataset
from ._dataset import post_resource
from ._job import get_job
from ._job import get_job_list
from ._job import get_job_logs
from ._job import job_submit
from ._job import stop_job
from ._project import delete_project
from ._project import get_project
Expand All @@ -40,9 +36,6 @@
from ._workflow import patch_workflowtask
from ._workflow import post_workflow
from ._workflow import post_workflowtask
from ._workflow import workflow_apply
from ._workflow import workflow_export
from ._workflow import workflow_import
from fractal_client import __VERSION__


Expand All @@ -59,7 +52,7 @@ def project(
subcmd: str,
batch: bool = False,
**kwargs,
) -> BaseInterface:
) -> Interface:

if subcmd == "new":
parameters = ["name"]
Expand All @@ -75,19 +68,11 @@ def project(
parameters = [
"project_id",
"new_name",
"make_read_only",
"remove_read_only",
]
function_kwargs = get_kwargs(parameters, kwargs)
iface = patch_project(client, **function_kwargs)
elif subcmd == "add-dataset":
parameters = [
"project_id",
"dataset_name",
"metadata",
"type",
"make_read_only",
]
parameters = ["project_id", "dataset_name", "zarr_dir", "filters"]
function_kwargs = get_kwargs(parameters, kwargs)
iface = post_dataset(client, batch=batch, **function_kwargs)
elif subcmd == "delete":
Expand All @@ -105,43 +90,24 @@ def dataset(
subcmd: str,
batch: bool = False,
**kwargs,
) -> BaseInterface:
) -> Interface:
if subcmd == "show":
parameters = ["project_id", "dataset_id"]
function_kwargs = get_kwargs(parameters, kwargs)
iface = get_dataset(client, **function_kwargs)
elif subcmd == "add-resource":
parameters = ["project_id", "dataset_id", "path"]
function_kwargs = get_kwargs(parameters, kwargs)
iface = post_resource(client, batch=batch, **function_kwargs)
elif subcmd == "rm-resource":
parameters = ["project_id", "dataset_id", "resource_id"]
function_kwargs = get_kwargs(parameters, kwargs)
iface = delete_resource(client, **function_kwargs)
elif subcmd == "edit":
parameters = [
"project_id",
"dataset_id",
"new_name",
"new_type",
"meta_file",
"make_read_only",
"remove_read_only",
"filters",
]
function_kwargs = get_kwargs(parameters, kwargs)
iface = patch_dataset(client, **function_kwargs)
elif subcmd == "delete":
parameters = ["project_id", "dataset_id"]
function_kwargs = get_kwargs(parameters, kwargs)
iface = delete_dataset(client, **function_kwargs)
elif subcmd == "history":
parameters = ["project_id", "dataset_id"]
function_kwargs = get_kwargs(parameters, kwargs)
iface = get_dataset_history(client, **function_kwargs)
elif subcmd == "status":
parameters = ["project_id", "dataset_id"]
function_kwargs = get_kwargs(parameters, kwargs)
iface = get_dataset_status(client, **function_kwargs)
else:
raise NoCommandError(f"Command dataset {subcmd} not found")
return iface
Expand All @@ -152,7 +118,7 @@ def task(
subcmd: str,
batch: bool = False,
**kwargs,
) -> BaseInterface:
) -> Interface:

if subcmd == "list":
iface = get_task_list(client)
Expand Down Expand Up @@ -214,7 +180,7 @@ def workflow(
subcmd: str,
batch: bool = False,
**kwargs,
) -> BaseInterface:
) -> Interface:
if subcmd == "show":
parameters = ["project_id", "workflow_id"]
function_kwargs = get_kwargs(parameters, kwargs)
Expand Down Expand Up @@ -243,8 +209,11 @@ def workflow(
"task_name",
"task_version",
"order",
"args_file",
"meta_file",
"args_non_parallel",
"args_parallel",
"input_filters",
"meta_parallel",
"meta_non_parallel",
]
function_kwargs = get_kwargs(parameters, kwargs)
iface = post_workflowtask(client, batch=batch, **function_kwargs)
Expand All @@ -253,35 +222,18 @@ def workflow(
"project_id",
"workflow_id",
"workflow_task_id",
"args_file",
"meta_file",
"input_filters",
"args_non_parallel",
"args_parallel",
"meta_parallel",
"meta_non_parallel",
]
function_kwargs = get_kwargs(parameters, kwargs)
iface = patch_workflowtask(client, **function_kwargs)
elif subcmd == "rm-task":
parameters = ["project_id", "workflow_id", "workflow_task_id"]
function_kwargs = get_kwargs(parameters, kwargs)
iface = delete_workflowtask(client, **function_kwargs)
elif subcmd == "apply":
parameters = [
"project_id",
"workflow_id",
"input_dataset_id",
"output_dataset_id",
"worker_init",
"first_task_index",
"last_task_index",
]
function_kwargs = get_kwargs(parameters, kwargs)
iface = workflow_apply(client, batch=batch, **function_kwargs)
elif subcmd == "import":
parameters = ["project_id", "json_file"]
function_kwargs = get_kwargs(parameters, kwargs)
iface = workflow_import(client, batch=batch, **function_kwargs)
elif subcmd == "export":
parameters = ["project_id", "workflow_id", "json_file"]
function_kwargs = get_kwargs(parameters, kwargs)
iface = workflow_export(client, **function_kwargs)
else:
raise NoCommandError(f"Command workflow {subcmd} not found")
return iface
Expand All @@ -292,7 +244,7 @@ def job(
subcmd: str,
batch: bool = False,
**kwargs,
) -> BaseInterface:
) -> Interface:
if subcmd == "list":
parameters = ["project_id"]
function_kwargs = get_kwargs(parameters, kwargs)
Expand All @@ -309,16 +261,27 @@ def job(
parameters = ["project_id", "job_id"]
function_kwargs = get_kwargs(parameters, kwargs)
iface = stop_job(client, **function_kwargs)
elif subcmd == "submit":
parameters = [
"project_id",
"workflow_id",
"dataset_id",
"worker_init",
"first_task_index",
"last_task_index",
]
function_kwargs = get_kwargs(parameters, kwargs)
iface = job_submit(client, batch=batch, **function_kwargs)
else:
raise NoCommandError(f"Command job {subcmd} not found")
return iface


def version(client: Client, **kwargs) -> PrintInterface:
def version(client: Client, **kwargs) -> Interface:
res = client.get(f"{settings.FRACTAL_SERVER}/api/alive/")
data = res.json()

return PrintInterface(
return Interface(
retcode=0,
data=(
f"Fractal client\n\tversion: {__VERSION__}\n"
Expand All @@ -331,7 +294,7 @@ def version(client: Client, **kwargs) -> PrintInterface:

def user(
client: AuthClient, subcmd: str, batch: bool = False, **kwargs
) -> BaseInterface:
) -> Interface:
if subcmd == "register":
parameters = [
"new_email",
Expand Down
Loading

0 comments on commit a4ab987

Please sign in to comment.