( inputFilePath: string, options: ReadAndConvertMarimoFileOptions )
| 449 | * @returns A DeepnoteFile object |
| 450 | */ |
| 451 | export async function readAndConvertMarimoFile( |
| 452 | inputFilePath: string, |
| 453 | options: ReadAndConvertMarimoFileOptions |
| 454 | ): Promise<DeepnoteFile> { |
| 455 | let app: MarimoAppWithOutputs |
| 456 | |
| 457 | try { |
| 458 | const content = await fs.readFile(inputFilePath, 'utf-8') |
| 459 | const parsedApp = parseMarimoFormat(content) |
| 460 | |
| 461 | // Try to load outputs from Marimo session cache |
| 462 | const outputs = await getMarimoOutputsFromCache(inputFilePath) |
| 463 | |
| 464 | app = { |
| 465 | filename: basename(inputFilePath), |
| 466 | app: parsedApp, |
| 467 | outputs: outputs ?? undefined, |
| 468 | } |
| 469 | } catch (err) { |
| 470 | const errorMessage = err instanceof Error ? err.message : String(err) |
| 471 | const errorStack = err instanceof Error ? err.stack : undefined |
| 472 | throw new FileReadError(`Failed to read or parse file ${basename(inputFilePath)}: ${errorMessage}`, { |
| 473 | cause: errorStack ? { originalError: err, stack: errorStack } : err, |
| 474 | filePath: inputFilePath, |
| 475 | }) |
| 476 | } |
| 477 | |
| 478 | return convertMarimoAppToDeepnoteFile(app, { |
| 479 | projectName: options.projectName, |
| 480 | projectId: options.projectId, |
| 481 | }) |
| 482 | } |
| 483 | |
| 484 | /** |
| 485 | * Converts a single Marimo (.py) file into a single Deepnote project file. |
no test coverage detected