marimo-on-fastapi / nb /prod_files.py
pup-py's picture
try setup cell
d0c117f
import marimo
__generated_with = "0.19.7"
app = marimo.App(width="full", app_title="๐ŸŽ Files")
with app.setup:
from datetime import datetime
from pathlib import Path
import marimo as mo
import sys
@app.function
def foo(p: Path):
pass
@app.cell
def _():
# internal imports
ROOT = Path(__file__).parent.parent
sys.path.append(ROOT.as_posix())
from src.marimo_apps import UI
return (UI,)
@app.class_definition
class FileManager:
def __init__(self, root_path: Path):
self.root_path = root_path
self.current_path = root_path
self.get_files()
def get_files(self):
self.files = []
self.paths = sorted(
self.current_path.iterdir(),
key=lambda p: (not p.is_dir(), p.name.lower()),
)
for p in self.paths:
stat = p.stat()
if p.is_dir():
size = ""
else:
size = stat.st_size
file = {
"name": p.name,
"size": size,
"mtime": datetime.fromtimestamp(stat.st_mtime).strftime(
"%Y-%m-%d %H:%M:%S"
),
}
self.files.append(file)
def _display_(self):
return mo.ui.table(
self.files, label=f"### {self.current_path}/", pagination=False
)
@app.cell
def _(UI):
md = mo.md("""
# Yes, Notebooks In Production | PyCon 2026
## File Browser
""")
mo.hstack([UI.NAV, md], widths=[1, 5])
return
@app.cell
def _():
fm = FileManager(Path("."))
fm
return
@app.cell
def _(UI):
UI.BUILD_DETAILS
return
if __name__ == "__main__":
app.run()