MCPcopy
hub / github.com/marimo-team/marimo / new

Function new

marimo/_cli/cli.py:732–830  ·  view source on GitHub ↗
(
    port: int | None,
    host: str,
    proxy: str | None,
    headless: bool,
    token: bool,
    token_password: str | None,
    token_password_file: str | None,
    base_url: str,
    sandbox: bool | None,
    skew_protection: bool,
    timeout: float | None,
    prompt: str | None,
)

Source from the content-addressed store, hash-verified

730)
731@click.argument("prompt", required=False)
732def new(
733 port: int | None,
734 host: str,
735 proxy: str | None,
736 headless: bool,
737 token: bool,
738 token_password: str | None,
739 token_password_file: str | None,
740 base_url: str,
741 sandbox: bool | None,
742 skew_protection: bool,
743 timeout: float | None,
744 prompt: str | None,
745) -> None:
746 if sandbox:
747 from marimo._cli.sandbox import run_in_sandbox
748
749 # TODO: consider adding recommended as well
750 run_in_sandbox(sys.argv[1:], name=None, additional_features=["lsp"])
751 return
752
753 workspace: NotebookWorkspace | None = None
754
755 if prompt is None:
756 # We support unix-style prompting, cat prompt.txt | marimo new
757 prompt = _get_stdin_contents()
758
759 if prompt is not None:
760 import tempfile
761
762 from marimo._ai.text_to_notebook import text_to_notebook
763
764 try:
765 _maybe_path = Path(prompt)
766 if _maybe_path.is_file():
767 prompt = _maybe_path.read_text(encoding="utf-8")
768 except OSError:
769 # is_file() fails when, for example, the "filename" (prompt) is too long
770 pass
771
772 temp_file = None
773 try:
774 notebook_content = text_to_notebook(prompt)
775 # On Windows, NamedTemporaryFile cannot be reopened unless
776 # delete=False.
777 with tempfile.NamedTemporaryFile(
778 suffix=".py", mode="w", encoding="utf-8", delete=False
779 ) as temp_file:
780 temp_file.write(notebook_content)
781 workspace = infer_workspace(temp_file.name)
782
783 def _cleanup() -> None:
784 try:
785 os.unlink(temp_file.name)
786 except Exception:
787 pass
788
789 atexit.register(_cleanup)

Callers

nothing calls this directly

Calls 13

run_in_sandboxFunction · 0.90
text_to_notebookFunction · 0.90
infer_workspaceFunction · 0.90
EmptyWorkspaceClass · 0.90
startFunction · 0.90
resolve_tokenFunction · 0.90
choose_startup_tipFunction · 0.90
_get_stdin_contentsFunction · 0.85
is_fileMethod · 0.80
unlinkMethod · 0.80
read_textMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected