From 18f312eb8b3dee262fb512af7e7ec3996674c4d4 Mon Sep 17 00:00:00 2001 From: David Brochart Date: Wed, 6 Sep 2023 16:02:23 +0200 Subject: [PATCH] Add default values to CLI callback (#349) * Add default values to CLI callback * Remove try/except when launching jupyverse --- jupyverse_api/jupyverse_api/cli.py | 32 +++++++++---------- jupyverse_api/jupyverse_api/main/__init__.py | 2 +- .../fps_auth_jupyterhub/launch.py | 23 ++++++------- 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/jupyverse_api/jupyverse_api/cli.py b/jupyverse_api/jupyverse_api/cli.py index 135f5f08..3a10f5cc 100644 --- a/jupyverse_api/jupyverse_api/cli.py +++ b/jupyverse_api/jupyverse_api/cli.py @@ -1,5 +1,5 @@ import pkg_resources -from typing import List +from typing import List, Tuple import rich_click as click from asphalt.core.cli import run @@ -45,31 +45,31 @@ help="Disable plugin.", ) def main( - open_browser: bool, - host: str, - port: int, - set_: List[str], - disable: List[str], - allow_origin: List[str], + open_browser: bool = False, + host: str = "127.0.0.1", + port: int = 8000, + set_: Tuple[str, ...] = (), + disable: Tuple[str, ...] = (), + allow_origin: Tuple[str, ...] = (), ) -> None: - set_ = list(set_) - for i, s in enumerate(set_): - set_[i] = f"component.components.{s}" - set_.append(f"component.open_browser={open_browser}") - set_.append(f"component.host={host}") - set_.append(f"component.port={port}") - set_.append(f"component.allow_origin={allow_origin}") + set_list: List[str] = list(set_) + for i, s in enumerate(set_list): + set_list[i] = f"component.components.{s}" + set_list.append(f"component.open_browser={open_browser}") + set_list.append(f"component.host={host}") + set_list.append(f"component.port={port}") + set_list.append(f"component.allow_origin={allow_origin}") config = get_config(disable) run.callback( unsafe=False, loop=None, - set_=set_, + set_=set_list, service=None, configfile=[config], ) # type: ignore -def get_config(disable: List[str]) -> str: +def get_config(disable: Tuple[str, ...]) -> str: jupyverse_components = [ ep.name for ep in pkg_resources.iter_entry_points(group="jupyverse.components") diff --git a/jupyverse_api/jupyverse_api/main/__init__.py b/jupyverse_api/jupyverse_api/main/__init__.py index 25813044..cfbaa3a3 100644 --- a/jupyverse_api/jupyverse_api/main/__init__.py +++ b/jupyverse_api/jupyverse_api/main/__init__.py @@ -40,7 +40,7 @@ def __init__( app: FastAPI | str | None = None, host: str = "127.0.0.1", port: int = 8000, - allow_origin: Tuple = (), + allow_origin: Tuple[str, ...] = (), open_browser: bool = False, query_params: Dict[str, Any] | None = None, debug: bool | None = None, diff --git a/plugins/auth_jupyterhub/fps_auth_jupyterhub/launch.py b/plugins/auth_jupyterhub/fps_auth_jupyterhub/launch.py index cdb91717..e753b0bf 100644 --- a/plugins/auth_jupyterhub/fps_auth_jupyterhub/launch.py +++ b/plugins/auth_jupyterhub/fps_auth_jupyterhub/launch.py @@ -7,16 +7,13 @@ def launch(): service_url = unquote(os.environ.get("JUPYTERHUB_SERVICE_URL")) url = urlparse(service_url) - try: - return main.callback( - open_browser=True, - host=url.hostname, - port=url.port, - set_=[ - f"frontend.base_url={url.path}", - f"app.mount_path={url.path}", - ], - disable=[], - ) - except Exception: - return + return main.callback( + open_browser=True, + host=url.hostname, + port=url.port, + set_=( + f"frontend.base_url={url.path}", + f"app.mount_path={url.path}", + ), + disable=[], + )