Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: marimo config to follow_symlink in StaticFiles #1327

Merged
merged 2 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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", {})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure how to get the MarimoConfig from a top-level context like this. Most call sites seem to read it off an existing object. Is there a better way than re-instantiating a UserConfigManager?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the best way given the current setup - and fine as is


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
Loading