MCPcopy Create free account
hub / github.com/deepnote/vscode-deepnote / executeCommand

Method executeCommand

src/notebooks/export/exportBase.node.ts:45–123  ·  view source on GitHub ↗
(
        sourceDocument: NotebookDocument,
        target: Uri,
        format: ExportFormat,
        interpreter: PythonEnvironment | undefined,
        token: CancellationToken
    )

Source from the content-addressed store, hash-verified

43
44 @reportAction(ReportableAction.PerformingExport)
45 public async executeCommand(
46 sourceDocument: NotebookDocument,
47 target: Uri,
48 format: ExportFormat,
49 interpreter: PythonEnvironment | undefined,
50 token: CancellationToken
51 ): Promise<void> {
52 if (token.isCancellationRequested) {
53 return;
54 }
55
56 interpreter = await this.exportInterpreterFinder.getExportInterpreter(interpreter);
57
58 if (format === ExportFormat.python) {
59 const contents = await this.importer.importFromFile(sourceDocument.uri, interpreter);
60 await this.fs.writeFile(target, contents);
61 return;
62 }
63
64 let contents = await this.exportUtil.getContent(sourceDocument);
65
66 if (format === ExportFormat.pdf) {
67 // When exporting to PDF we need to remove any SVG output. This is due to an error
68 // with nbconvert and a dependency of its called InkScape.
69 contents = await removeSvgs(contents);
70 }
71
72 /* Need to make a temp directory here, instead of just a temp file. This is because
73 we need to store the contents of the notebook in a file that is named the same
74 as what we want the title of the exported file to be. To ensure this file path will be unique
75 we store it in a temp directory. The name of the file matters because when
76 exporting to certain formats the filename is used within the exported document as the title. */
77 const tempDir = await new ExportUtilNode().generateTempDir();
78 const source = await this.makeSourceFile(target, contents, tempDir);
79
80 const service = await this.getExecutionService(source, interpreter);
81 if (!service) {
82 return;
83 }
84
85 if (token.isCancellationRequested) {
86 return;
87 }
88
89 const tempTarget = await this.fs.createTemporaryLocalFile(path.extname(target.fsPath));
90 const args = [
91 source.fsPath,
92 '--to',
93 format,
94 '--output',
95 path.basename(tempTarget.filePath),
96 '--output-dir',
97 path.dirname(tempTarget.filePath),
98 '--debug'
99 ];
100 const result = await service.execModule('jupyter', ['nbconvert'].concat(args), {
101 throwOnStdErr: false,
102 encoding: 'utf8',

Callers

nothing calls this directly

Calls 15

makeSourceFileMethod · 0.95
getExecutionServiceMethod · 0.95
removeSvgsFunction · 0.90
getExportInterpreterMethod · 0.80
getContentMethod · 0.80
importFromFileMethod · 0.65
writeFileMethod · 0.65
extnameMethod · 0.65
basenameMethod · 0.65
dirnameMethod · 0.65
execModuleMethod · 0.65

Tested by

no test coverage detected