Skip to content

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.

improvement: set default config, if missing (#3004)

Myles Scolnickffc6508d6d5a
diff --git a/marimo/_cli/config/commands.py b/marimo/_cli/config/commands.py
index 46bcd90362..fce7e8fd0d 100644
--- a/marimo/_cli/config/commands.py
+++ b/marimo/_cli/config/commands.py
@@ -24,6 +24,8 @@ def show() -> None:
import tomlkit
config_manager = UserConfigManager()
+ # Save config if doesn't exist
+ config_manager.save_config_if_missing()
echo(f"User config from {green(config_manager.get_config_path())}\n")
toml_string = tomlkit.dumps(config_manager.get_config())
echo(highlight_toml_headers(toml_string))
diff --git a/marimo/_config/manager.py b/marimo/_config/manager.py
index 1b31140d34..df5c940df3 100644
--- a/marimo/_config/manager.py
+++ b/marimo/_config/manager.py
@@ -1,10 +1,12 @@
# Copyright 2024 Marimo. All rights reserved.
from __future__ import annotations
+import os
from typing import Optional
from marimo import _loggers
from marimo._config.config import (
+ DEFAULT_CONFIG,
MarimoConfig,
PartialMarimoConfig,
mask_secrets,
@@ -43,6 +45,14 @@ class UserConfigManager:
self.config = merge_default_config(merged)
return self.config
+ def save_config_if_missing(self) -> None:
+ try:
+ config_path = self.get_config_path()
+ if not os.path.exists(config_path):
+ self.save_config(DEFAULT_CONFIG)
+ except Exception as e:
+ LOGGER.warning("Failed to save config: %s", e)
+
def get_config(self, hide_secrets: bool = True) -> MarimoConfig:
if hide_secrets:
return mask_secrets(self.config)