Skip to content

Commit

Permalink
Add default values to CLI callback (#349)
Browse files Browse the repository at this point in the history
* Add default values to CLI callback

* Remove try/except when launching jupyverse
  • Loading branch information
davidbrochart authored Sep 6, 2023
1 parent 30479a9 commit 18f312e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 30 deletions.
32 changes: 16 additions & 16 deletions jupyverse_api/jupyverse_api/cli.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion jupyverse_api/jupyverse_api/main/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 10 additions & 13 deletions plugins/auth_jupyterhub/fps_auth_jupyterhub/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[],
)

0 comments on commit 18f312e

Please sign in to comment.