MCPcopy
hub / github.com/marimo-team/marimo / save

Method save

marimo/_session/notebook/file_manager.py:404–462  ·  view source on GitHub ↗

Save the notebook. Args: request: Save request with cell data and options Returns: Serialized notebook content Raises: HTTPException: If save fails or tries to rename

(self, request: SaveNotebookRequest)

Source from the content-addressed store, hash-verified

402 return ""
403
404 def save(self, request: SaveNotebookRequest) -> str:
405 """Save the notebook.
406
407 Args:
408 request: Save request with cell data and options
409
410 Returns:
411 Serialized notebook content
412
413 Raises:
414 HTTPException: If save fails or tries to rename
415 """
416 cell_ids, codes, configs, names, filename, layout = (
417 request.cell_ids,
418 request.codes,
419 request.configs,
420 request.names,
421 request.filename,
422 request.layout,
423 )
424
425 filename_path = Path(canonicalize_filename(filename))
426
427 with self._save_lock:
428 # Update app with new cell data
429 self.app.with_data(
430 cell_ids=cell_ids,
431 codes=codes,
432 names=names,
433 configs=configs,
434 )
435
436 if self.is_notebook_named and not self._is_same_path(
437 filename_path
438 ):
439 raise HTTPException(
440 status_code=HTTPStatus.BAD_REQUEST,
441 detail="Save handler cannot rename files.",
442 )
443
444 # Save layout if provided
445 if layout is not None:
446 app_dir = filename_path.parent
447 app_name = filename_path.name
448 layout_filename = save_layout_config(
449 app_dir, app_name, LayoutConfig(**layout)
450 )
451 self.app.update_config({"layout_file": layout_filename})
452 else:
453 # Remove the layout from the config
454 self.app.update_config({"layout_file": None})
455
456 if request.persist:
457 self._invalidate_autosaves()
458 return self._save_file(
459 filename_path,
460 notebook=self.app.to_ir(),
461 persist=request.persist,

Calls 10

_is_same_pathMethod · 0.95
_invalidate_autosavesMethod · 0.95
_save_fileMethod · 0.95
HTTPExceptionClass · 0.90
save_layout_configFunction · 0.90
LayoutConfigClass · 0.90
canonicalize_filenameFunction · 0.85
with_dataMethod · 0.80
update_configMethod · 0.80
to_irMethod · 0.45