Skip to content

Commit 9e4e356

Browse files
authored
Fixes to exporting of notebook to html (#12882)
Ensure we have file extensions for the source ipynb Ensure we have file extensions for the target html/pdf files Misc cleanup
1 parent 336842b commit 9e4e356

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

src/client/datascience/export/exportBase.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class ExportBase implements IExport {
4444
throw new Error(result.stderr);
4545
} else if (oldFileExists) {
4646
// If we exported to a file that already exists we need to check that
47-
// this file was actually overriden during export
47+
// this file was actually overridden during export
4848
const newFileTime = (await this.fileSystem.stat(target.fsPath)).mtime;
4949
if (newFileTime === oldFileTime) {
5050
throw new Error(result.stderr);
@@ -53,8 +53,13 @@ export class ExportBase implements IExport {
5353
}
5454

5555
protected async getExecutionService(source: Uri): Promise<IPythonExecutionService | undefined> {
56+
const interpreter = await this.jupyterService.getSelectedInterpreter();
57+
if (!interpreter) {
58+
return;
59+
}
5660
return this.pythonExecutionFactory.createActivatedEnvironment({
5761
resource: source,
62+
interpreter,
5863
allowEnvironmentFetchExceptions: false,
5964
bypassCondaExecution: true
6065
});

src/client/datascience/export/exportManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class ExportManager implements IExportManager {
4242
// exporting to certain formats the filename is used within the exported document as the title.
4343
const fileName = path.basename(target.fsPath, path.extname(target.fsPath));
4444
const tempDir = await this.exportUtil.generateTempDir();
45-
const sourceFilePath = await this.exportUtil.makeFileInDirectory(model, fileName, tempDir.path);
45+
const sourceFilePath = await this.exportUtil.makeFileInDirectory(model, `${fileName}.ipynb`, tempDir.path);
4646
const source = Uri.file(sourceFilePath);
4747

4848
if (format === ExportFormat.pdf) {

src/client/datascience/export/exportManagerFilePicker.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,32 @@ export class ExportManagerFilePicker implements IExportManagerFilePicker {
2727
): Promise<Uri | undefined> {
2828
// map each export method to a set of file extensions
2929
let fileExtensions;
30+
let extension: string | undefined;
3031
switch (format) {
3132
case ExportFormat.python:
3233
fileExtensions = PythonExtensions;
34+
extension = '.py';
3335
break;
3436

3537
case ExportFormat.pdf:
38+
extension = '.pdf';
3639
fileExtensions = PDFExtensions;
3740
break;
3841

3942
case ExportFormat.html:
43+
extension = '.html';
4044
fileExtensions = HTMLExtensions;
4145
break;
4246

4347
default:
4448
return;
4549
}
4650

47-
const notebookFileName = defaultFileName
51+
const targetFileName = defaultFileName
4852
? defaultFileName
49-
: path.basename(source.fsPath, path.extname(source.fsPath));
53+
: `${path.basename(source.fsPath, path.extname(source.fsPath))}${extension}`;
5054

51-
const dialogUri = Uri.file(path.join(this.getLastFileSaveLocation().fsPath, notebookFileName));
55+
const dialogUri = Uri.file(path.join(this.getLastFileSaveLocation().fsPath, targetFileName));
5256
const options: SaveDialogOptions = {
5357
defaultUri: dialogUri,
5458
saveLabel: 'Export',

src/client/datascience/export/exportUtil.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ import * as uuid from 'uuid/v4';
66
import { CancellationTokenSource, Uri } from 'vscode';
77
import { IFileSystem, TemporaryDirectory } from '../../common/platform/types';
88
import { sleep } from '../../common/utils/async';
9-
import { ICell, IDataScienceErrorHandler, INotebookExporter, INotebookModel, INotebookStorage } from '../types';
9+
import { ICell, INotebookExporter, INotebookModel, INotebookStorage } from '../types';
1010

1111
@injectable()
1212
export class ExportUtil {
1313
constructor(
1414
@inject(IFileSystem) private fileSystem: IFileSystem,
15-
@inject(IDataScienceErrorHandler) private readonly errorHandler: IDataScienceErrorHandler,
1615
@inject(INotebookStorage) private notebookStorage: INotebookStorage,
1716
@inject(INotebookExporter) private jupyterExporter: INotebookExporter
1817
) {}
@@ -44,12 +43,7 @@ export class ExportUtil {
4443
public async makeFileInDirectory(model: INotebookModel, fileName: string, dirPath: string): Promise<string> {
4544
const newFilePath = path.join(dirPath, fileName);
4645

47-
try {
48-
const content = model ? model.getContent() : '';
49-
await this.fileSystem.writeFile(newFilePath, content, 'utf-8');
50-
} catch (e) {
51-
await this.errorHandler.handleError(e);
52-
}
46+
await this.fileSystem.writeFile(newFilePath, model.getContent(), 'utf-8');
5347

5448
return newFilePath;
5549
}

0 commit comments

Comments
 (0)