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
Ask for confirmation if file name already exist instead of overriding it (#3987)
xenium95a290be9e30
diff --git a/marimo/_cli/convert/commands.py b/marimo/_cli/convert/commands.pyindex da845f688d..a81a667e2b 100644--- a/marimo/_cli/convert/commands.py+++ b/marimo/_cli/convert/commands.py@@ -8,6 +8,7 @@ import clickfrom marimo._cli.convert.markdown import convert_from_mdfrom marimo._cli.convert.utils import load_external_filefrom marimo._cli.print import echo+from marimo._cli.utils import prompt_to_overwritefrom marimo._convert.ipynb import convert_from_ipynbfrom marimo._utils.paths import maybe_make_dirs@@ -63,9 +64,11 @@ def convert(notebook = convert_from_md(text)if output:- # Make dirs if needed- maybe_make_dirs(output)- Path(output).write_text(notebook, encoding="utf-8")- echo(f"Converted notebook saved to {output}")+ output_path = Path(output)+ if prompt_to_overwrite(output_path):+ # Make dirs if needed+ maybe_make_dirs(output)+ Path(output).write_text(notebook, encoding="utf-8")+ echo(f"Converted notebook saved to {output}")else:echo(notebook)diff --git a/marimo/_cli/export/commands.py b/marimo/_cli/export/commands.pyindex 68dec110ce..da4e64e560 100644--- a/marimo/_cli/export/commands.py+++ b/marimo/_cli/export/commands.py@@ -9,6 +9,7 @@ import clickfrom marimo._cli.parse_args import parse_argsfrom marimo._cli.print import echo, green+from marimo._cli.utils import prompt_to_overwritefrom marimo._dependencies.dependencies import DependencyManagerfrom marimo._server.export import (ExportResult,@@ -63,6 +64,11 @@ def watch_and_export(echo(data)return+ if output:+ output_path = Path(output)+ if not prompt_to_overwrite(output_path):+ return+# No watch, just run onceif not watch:result = export_callback(marimo_path)diff --git a/marimo/_cli/utils.py b/marimo/_cli/utils.pynew file mode 100644index 0000000000..13152b3456--- /dev/null+++ b/marimo/_cli/utils.py@@ -0,0 +1,26 @@+# Copyright 2024 Marimo. All rights reserved.++from pathlib import Path+from sys import stdout++import click++from marimo._config.settings import GLOBAL_SETTINGS+++def prompt_to_overwrite(path: Path) -> bool:+ if GLOBAL_SETTINGS.YES:+ return True++ # Check if not in an interactive terminal+ # default to False+ if not stdout.isatty():+ return True++ if path.exists():+ return click.confirm(+ f"Warning: The file '{path}' already exists. Overwrite?",+ default=False,+ )++ return True