MCPcopy
hub / github.com/deepnote/deepnote / parseRunnableFileContent

Function parseRunnableFileContent

packages/convert/src/load-runnable-file.ts:73–195  ·  view source on GitHub ↗
(content: string, absolutePath: string)

Source from the content-addressed store, hash-verified

71 * @throws LoadRunnableFileError for unsupported extensions and parse/format failures
72 */
73export function parseRunnableFileContent(content: string, absolutePath: string): LoadedRunnableFile {
74 const ext = path.extname(absolutePath).toLowerCase()
75
76 if (!isRunnableExtension(ext)) {
77 throw unsupportedExtensionError(ext)
78 }
79
80 const filename = path.basename(absolutePath)
81 const projectName = path.basename(absolutePath, ext)
82
83 if (ext === '.deepnote') {
84 let file: DeepnoteFile
85 try {
86 file = deserializeDeepnoteFile(content)
87 } catch (parseError) {
88 const message = parseError instanceof Error ? parseError.message : String(parseError)
89 throw new LoadRunnableFileError(`Failed to parse .deepnote file: ${absolutePath}\n\n` + `Parse error: ${message}`)
90 }
91
92 return {
93 file,
94 originalPath: absolutePath,
95 format: 'deepnote',
96 wasConverted: false,
97 }
98 }
99
100 if (ext === '.ipynb') {
101 let notebook: JupyterNotebook
102 try {
103 notebook = JSON.parse(content) as JupyterNotebook
104 } catch (parseError) {
105 const message = parseError instanceof Error ? parseError.message : String(parseError)
106 throw new LoadRunnableFileError(
107 `Invalid Jupyter notebook: ${absolutePath}\n\n` + `The file is not valid JSON. Parse error: ${message}`
108 )
109 }
110
111 const file = convertJupyterNotebookToDeepnote({ filename, notebook }, { projectName })
112 return {
113 file,
114 originalPath: absolutePath,
115 format: 'jupyter',
116 wasConverted: true,
117 }
118 }
119
120 if (ext === '.qmd') {
121 let document: ReturnType<typeof parseQuartoFormat>
122 try {
123 document = parseQuartoFormat(content)
124 } catch (parseError) {
125 const message = parseError instanceof Error ? parseError.message : String(parseError)
126 throw new LoadRunnableFileError(
127 `Failed to parse Quarto document: ${absolutePath}\n\n` + `Parse error: ${message}`
128 )
129 }
130 const file = convertQuartoDocumentToDeepnote({ filename, document }, { projectName })

Callers 2

loadRunnableFileFunction · 0.85

Calls 11

deserializeDeepnoteFileFunction · 0.90
parseQuartoFormatFunction · 0.90
detectFormatFunction · 0.90
parseMarimoFormatFunction · 0.90
parsePercentFormatFunction · 0.90
isRunnableExtensionFunction · 0.85

Tested by

no test coverage detected