Skip to content

Commit

Permalink
fix: marimo config to follow_symlink in StaticFiles (#1327)
Browse files Browse the repository at this point in the history
* draft: potential fix for #1298.

* update snapshot tests
  • Loading branch information
Ubehebe committed May 7, 2024
1 parent a55c9ea commit 22a9390
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
8 changes: 7 additions & 1 deletion marimo/_config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,12 @@ class ServerConfig(TypedDict):
- `browser`: the web browser to use. `"default"` or a browser registered
with Python's webbrowser module (eg, `"firefox"` or `"chrome"`)
- `follow_symlink`: if true, the server will follow symlinks it finds
inside its static assets directory.
"""

browser: Union[Literal["default"], str]
follow_symlink: bool


class PackageManagementConfig(TypedDict):
Expand Down Expand Up @@ -199,7 +202,10 @@ class MarimoConfig(TypedDict):
"format_on_save": False,
},
"package_management": {"manager": "pip"},
"server": {"browser": "default"},
"server": {
"browser": "default",
"follow_symlink": False,
},
}


Expand Down
8 changes: 7 additions & 1 deletion marimo/_server/api/endpoints/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from starlette.staticfiles import StaticFiles

from marimo import _loggers
from marimo._config.manager import UserConfigManager
from marimo._runtime.virtual_file import EMPTY_VIRTUAL_FILE, read_virtual_file
from marimo._server.api.deps import AppState
from marimo._server.router import APIRouter
Expand All @@ -31,9 +32,14 @@
# Root directory for static assets
root = os.path.realpath(str(import_files("marimo").joinpath("_static")))

config = UserConfigManager().get_config().get("server", {})

router.mount(
"/assets",
app=StaticFiles(directory=os.path.join(root, "assets")),
app=StaticFiles(
directory=os.path.join(root, "assets"),
follow_symlink=config.get("follow_symlink", False),
),
name="assets",
)

Expand Down
2 changes: 1 addition & 1 deletion tests/_server/templates/snapshots/export1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<marimo-filename hidden>notebook.py</marimo-filename>
<marimo-mode data-mode='read' hidden></marimo-mode>
<marimo-version data-version='0.0.0' hidden></marimo-version>
<marimo-user-config data-config='{"completion": {"activate_on_typing": true, "copilot": false}, "display": {"cell_output": "above", "code_editor_font_size": 14, "theme": "light"}, "formatting": {"line_length": 79}, "keymap": {"preset": "default"}, "package_management": {"manager": "pip"}, "runtime": {"auto_instantiate": true, "auto_reload": "off", "on_cell_change": "autorun"}, "save": {"autosave": "after_delay", "autosave_delay": 1000, "format_on_save": false}, "server": {"browser": "default"}}' hidden></marimo-user-config>
<marimo-user-config data-config='{"completion": {"activate_on_typing": true, "copilot": false}, "display": {"cell_output": "above", "code_editor_font_size": 14, "theme": "light"}, "formatting": {"line_length": 79}, "keymap": {"preset": "default"}, "package_management": {"manager": "pip"}, "runtime": {"auto_instantiate": true, "auto_reload": "off", "on_cell_change": "autorun"}, "save": {"autosave": "after_delay", "autosave_delay": 1000, "format_on_save": false}, "server": {"browser": "default", "follow_symlink": false}}' hidden></marimo-user-config>
<marimo-app-config data-config='{"app_title": null, "layout_file": null, "width": "normal"}' hidden></marimo-app-config>
<marimo-server-token data-token='token' hidden></marimo-server-token>
<title>notebook</title>
Expand Down
2 changes: 1 addition & 1 deletion tests/_server/templates/snapshots/export2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<marimo-filename hidden></marimo-filename>
<marimo-mode data-mode='read' hidden></marimo-mode>
<marimo-version data-version='0.0.0' hidden></marimo-version>
<marimo-user-config data-config='{"completion": {"activate_on_typing": true, "copilot": false}, "display": {"cell_output": "above", "code_editor_font_size": 14, "theme": "light"}, "formatting": {"line_length": 79}, "keymap": {"preset": "default"}, "package_management": {"manager": "pip"}, "runtime": {"auto_instantiate": true, "auto_reload": "off", "on_cell_change": "autorun"}, "save": {"autosave": "after_delay", "autosave_delay": 1000, "format_on_save": false}, "server": {"browser": "default"}}' hidden></marimo-user-config>
<marimo-user-config data-config='{"completion": {"activate_on_typing": true, "copilot": false}, "display": {"cell_output": "above", "code_editor_font_size": 14, "theme": "light"}, "formatting": {"line_length": 79}, "keymap": {"preset": "default"}, "package_management": {"manager": "pip"}, "runtime": {"auto_instantiate": true, "auto_reload": "off", "on_cell_change": "autorun"}, "save": {"autosave": "after_delay", "autosave_delay": 1000, "format_on_save": false}, "server": {"browser": "default", "follow_symlink": false}}' hidden></marimo-user-config>
<marimo-app-config data-config='{"app_title": null, "layout_file": null, "width": "normal"}' hidden></marimo-app-config>
<marimo-server-token data-token='token' hidden></marimo-server-token>
<title>marimo</title>
Expand Down
2 changes: 1 addition & 1 deletion tests/_server/templates/snapshots/export3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<marimo-filename hidden>notebook.py</marimo-filename>
<marimo-mode data-mode='read' hidden></marimo-mode>
<marimo-version data-version='0.0.0' hidden></marimo-version>
<marimo-user-config data-config='{"completion": {"activate_on_typing": true, "copilot": false}, "display": {"cell_output": "above", "code_editor_font_size": 14, "theme": "light"}, "formatting": {"line_length": 79}, "keymap": {"preset": "default"}, "package_management": {"manager": "pip"}, "runtime": {"auto_instantiate": true, "auto_reload": "off", "on_cell_change": "autorun"}, "save": {"autosave": "after_delay", "autosave_delay": 1000, "format_on_save": false}, "server": {"browser": "default"}}' hidden></marimo-user-config>
<marimo-user-config data-config='{"completion": {"activate_on_typing": true, "copilot": false}, "display": {"cell_output": "above", "code_editor_font_size": 14, "theme": "light"}, "formatting": {"line_length": 79}, "keymap": {"preset": "default"}, "package_management": {"manager": "pip"}, "runtime": {"auto_instantiate": true, "auto_reload": "off", "on_cell_change": "autorun"}, "save": {"autosave": "after_delay", "autosave_delay": 1000, "format_on_save": false}, "server": {"browser": "default", "follow_symlink": false}}' hidden></marimo-user-config>
<marimo-app-config data-config='{"app_title": null, "layout_file": null, "width": "normal"}' hidden></marimo-app-config>
<marimo-server-token data-token='token' hidden></marimo-server-token>
<title>notebook</title>
Expand Down

0 comments on commit 22a9390

Please sign in to comment.