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

Class ExportBase

src/notebooks/export/exportBase.node.ts:24–145  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22 */
23@injectable()
24export class ExportBase implements IExportBase {
25 constructor(
26 @inject(IPythonExecutionFactory) protected readonly pythonExecutionFactory: IPythonExecutionFactory,
27 @inject(IJupyterSubCommandExecutionService)
28 protected jupyterService: IJupyterSubCommandExecutionService,
29 @inject(IFileSystemNode) protected readonly fs: IFileSystemNode,
30 @inject(IExportUtil) protected readonly exportUtil: IExportUtil,
31 @inject(INotebookImporter) protected readonly importer: INotebookImporter,
32 @inject(ExportInterpreterFinder) private exportInterpreterFinder: ExportInterpreterFinder
33 ) {}
34
35 public async export(
36 _sourceDocument: NotebookDocument,
37 _target: Uri,
38 _interpreter: PythonEnvironment,
39 _token: CancellationToken
40 ): Promise<void> {
41 return;
42 }
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) {

Callers

nothing calls this directly

Calls 1

reportActionFunction · 0.90

Tested by

no test coverage detected