-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathnotebooks.py
More file actions
74 lines (63 loc) · 2.06 KB
/
Copy pathnotebooks.py
File metadata and controls
74 lines (63 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import secrets
import string
from pathlib import Path
from typing import Annotated, Literal
import typer
BASE_PATH = Path(__file__).resolve().parents[1] / "notebooks"
TOKEN_LENGTH = 32
NOTEBOOKS = {
"pipeline": BASE_PATH / "pipeline.py",
}
notebooks_app = typer.Typer(help="Start OpenHound Marimo notebooks")
def _generate_token(length: int = TOKEN_LENGTH) -> str:
alphabet = string.ascii_letters + string.digits
return "".join(secrets.choice(alphabet) for _ in range(length))
@notebooks_app.command()
def start(
notebook: Annotated[
Literal["pipeline"], typer.Argument(help="Notebook to start")
] = "pipeline",
host: Annotated[
str,
typer.Option("--host", "-h", help="Host for the Marimo server"),
] = "127.0.0.1",
port: Annotated[
int,
typer.Option("--port", "-p", help="Port for the Marimo server"),
] = 2718,
):
"""Start one of the bundled OpenHound Marimo notebooks."""
from rich.console import Console
console = Console()
try:
from marimo._server.file_router import AppFileRouter
from marimo._server.start import start
from marimo._server.tokens import AuthToken
from marimo._session.model import SessionMode
from marimo._utils.marimo_path import MarimoPath
except ImportError:
console.print(
"[red]Error:[/red] Marimo is not installed. Install OpenHound with Marimo extras using openhound\\[notebooks] [red]"
)
raise typer.Exit(1)
notebook_path = NOTEBOOKS[notebook]
start(
file_router=AppFileRouter.from_filename(MarimoPath(str(notebook_path))),
mode=SessionMode.RUN,
development_mode=False,
quiet=False,
include_code=False,
ttl_seconds=120,
headless=False,
port=port,
host=host,
proxy=None,
watch=False,
cli_args={},
argv=[],
base_url="",
allow_origins=None,
auth_token=AuthToken(_generate_token()),
redirect_console_to_browser=False,
skew_protection=True,
)