diff --git a/src/client/datascience/export/exportBase.ts b/src/client/datascience/export/exportBase.ts index 7bf957085fed..a5ed31449b51 100644 --- a/src/client/datascience/export/exportBase.ts +++ b/src/client/datascience/export/exportBase.ts @@ -44,7 +44,7 @@ export class ExportBase implements IExport { throw new Error(result.stderr); } else if (oldFileExists) { // If we exported to a file that already exists we need to check that - // this file was actually overriden during export + // this file was actually overridden during export const newFileTime = (await this.fileSystem.stat(target.fsPath)).mtime; if (newFileTime === oldFileTime) { throw new Error(result.stderr); @@ -53,8 +53,13 @@ export class ExportBase implements IExport { } protected async getExecutionService(source: Uri): Promise { + const interpreter = await this.jupyterService.getSelectedInterpreter(); + if (!interpreter) { + return; + } return this.pythonExecutionFactory.createActivatedEnvironment({ resource: source, + interpreter, allowEnvironmentFetchExceptions: false, bypassCondaExecution: true }); diff --git a/src/client/datascience/export/exportManager.ts b/src/client/datascience/export/exportManager.ts index 9aec833e9b15..dcfb47f80183 100644 --- a/src/client/datascience/export/exportManager.ts +++ b/src/client/datascience/export/exportManager.ts @@ -42,7 +42,7 @@ export class ExportManager implements IExportManager { // exporting to certain formats the filename is used within the exported document as the title. const fileName = path.basename(target.fsPath, path.extname(target.fsPath)); const tempDir = await this.exportUtil.generateTempDir(); - const sourceFilePath = await this.exportUtil.makeFileInDirectory(model, fileName, tempDir.path); + const sourceFilePath = await this.exportUtil.makeFileInDirectory(model, `${fileName}.ipynb`, tempDir.path); const source = Uri.file(sourceFilePath); if (format === ExportFormat.pdf) { diff --git a/src/client/datascience/export/exportManagerFilePicker.ts b/src/client/datascience/export/exportManagerFilePicker.ts index afb3e7ffb567..c92436c295dd 100644 --- a/src/client/datascience/export/exportManagerFilePicker.ts +++ b/src/client/datascience/export/exportManagerFilePicker.ts @@ -27,16 +27,20 @@ export class ExportManagerFilePicker implements IExportManagerFilePicker { ): Promise { // map each export method to a set of file extensions let fileExtensions; + let extension: string | undefined; switch (format) { case ExportFormat.python: fileExtensions = PythonExtensions; + extension = '.py'; break; case ExportFormat.pdf: + extension = '.pdf'; fileExtensions = PDFExtensions; break; case ExportFormat.html: + extension = '.html'; fileExtensions = HTMLExtensions; break; @@ -44,11 +48,11 @@ export class ExportManagerFilePicker implements IExportManagerFilePicker { return; } - const notebookFileName = defaultFileName + const targetFileName = defaultFileName ? defaultFileName - : path.basename(source.fsPath, path.extname(source.fsPath)); + : `${path.basename(source.fsPath, path.extname(source.fsPath))}${extension}`; - const dialogUri = Uri.file(path.join(this.getLastFileSaveLocation().fsPath, notebookFileName)); + const dialogUri = Uri.file(path.join(this.getLastFileSaveLocation().fsPath, targetFileName)); const options: SaveDialogOptions = { defaultUri: dialogUri, saveLabel: 'Export', diff --git a/src/client/datascience/export/exportUtil.ts b/src/client/datascience/export/exportUtil.ts index d7fe774d9923..f637bd8bd25c 100644 --- a/src/client/datascience/export/exportUtil.ts +++ b/src/client/datascience/export/exportUtil.ts @@ -6,13 +6,12 @@ import * as uuid from 'uuid/v4'; import { CancellationTokenSource, Uri } from 'vscode'; import { IFileSystem, TemporaryDirectory } from '../../common/platform/types'; import { sleep } from '../../common/utils/async'; -import { ICell, IDataScienceErrorHandler, INotebookExporter, INotebookModel, INotebookStorage } from '../types'; +import { ICell, INotebookExporter, INotebookModel, INotebookStorage } from '../types'; @injectable() export class ExportUtil { constructor( @inject(IFileSystem) private fileSystem: IFileSystem, - @inject(IDataScienceErrorHandler) private readonly errorHandler: IDataScienceErrorHandler, @inject(INotebookStorage) private notebookStorage: INotebookStorage, @inject(INotebookExporter) private jupyterExporter: INotebookExporter ) {} @@ -44,12 +43,7 @@ export class ExportUtil { public async makeFileInDirectory(model: INotebookModel, fileName: string, dirPath: string): Promise { const newFilePath = path.join(dirPath, fileName); - try { - const content = model ? model.getContent() : ''; - await this.fileSystem.writeFile(newFilePath, content, 'utf-8'); - } catch (e) { - await this.errorHandler.handleError(e); - } + await this.fileSystem.writeFile(newFilePath, model.getContent(), 'utf-8'); return newFilePath; }