A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
feat: add cli args to html export (#1151)
Akshay Agrawal604340cd9924
diff --git a/marimo/_cli/export/commands.py b/marimo/_cli/export/commands.pyindex cc9c2eae28..5efbaf1588 100644--- a/marimo/_cli/export/commands.py+++ b/marimo/_cli/export/commands.py@@ -6,6 +6,7 @@ from pathlib import Pathimport click+from marimo._cli.parse_args import parse_argsfrom marimo._cli.print import greenfrom marimo._server.export.utils import run_app_then_export_as_htmlfrom marimo._utils.file_watcher import FileWatcher@@ -24,6 +25,11 @@ Example:\b* marimo export html notebook.py -o notebook.html++Optionally pass CLI args to the notebook:++ \b+ * marimo export html notebook.py -o notebook.html -- -arg1 foo -arg2 bar""")@click.option(@@ -55,11 +61,13 @@ Example:""",)@click.argument("name", required=True)[email protected]("args", nargs=-1, type=click.UNPROCESSED)def html(name: str,include_code: bool,output: str,watch: bool,+ args: tuple[str],) -> None:"""Run a notebook and export it as an HTML file.@@ -80,10 +88,13 @@ def html(else:click.echo(html)+ cli_args = parse_args(args)# No watch, just run onceif not watch:(html, _filename) = asyncio.run(- run_app_then_export_as_html(name, include_code=include_code)+ run_app_then_export_as_html(+ name, include_code=include_code, cli_args=cli_args+ ))write_html(html)return@@ -93,7 +104,7 @@ def html(f"File {str(file_path)} changed. Re-exporting to {green(output)}")(html, _filename) = await run_app_then_export_as_html(- str(file_path), include_code=include_code+ str(file_path), include_code=include_code, cli_args=cli_args)write_html(html)diff --git a/marimo/_server/export/utils.py b/marimo/_server/export/utils.pyindex 8eedb144ae..0d231bb886 100644--- a/marimo/_server/export/utils.py+++ b/marimo/_server/export/utils.py@@ -7,7 +7,7 @@ from typing import Callablefrom marimo._config.manager import UserConfigManagerfrom marimo._messaging.ops import MessageOperationfrom marimo._messaging.types import KernelMessage-from marimo._runtime.requests import AppMetadata+from marimo._runtime.requests import AppMetadata, SerializedCLIArgsfrom marimo._server.export.exporter import Exporterfrom marimo._server.file_router import AppFileRouterfrom marimo._server.model import ConnectionState, SessionConsumer, SessionMode@@ -19,6 +19,7 @@ from marimo._server.sessions import Sessionasync def run_app_then_export_as_html(filename: str,include_code: bool,+ cli_args: SerializedCLIArgs | None = None,) -> tuple[str, str]:# Create a file router and file managerfile_router = AppFileRouter.from_filename(filename)@@ -59,7 +60,9 @@ async def run_app_then_export_as_html(session_consumer=NoopSessionConsumer(),mode=SessionMode.RUN,app_metadata=AppMetadata(- query_params={}, filename=file_manager.path, cli_args={}+ query_params={},+ filename=file_manager.path,+ cli_args=cli_args if cli_args is not None else {},),app_file_manager=file_manager,user_config_manager=config,