Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/client/datascience/export/exportBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -53,8 +53,13 @@ export class ExportBase implements IExport {
}

protected async getExecutionService(source: Uri): Promise<IPythonExecutionService | undefined> {
const interpreter = await this.jupyterService.getSelectedInterpreter();
if (!interpreter) {
return;
}
return this.pythonExecutionFactory.createActivatedEnvironment({
resource: source,
interpreter,
allowEnvironmentFetchExceptions: false,
bypassCondaExecution: true
});
Expand Down
2 changes: 1 addition & 1 deletion src/client/datascience/export/exportManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was required on mac

const source = Uri.file(sourceFilePath);

if (format === ExportFormat.pdf) {
Expand Down
10 changes: 7 additions & 3 deletions src/client/datascience/export/exportManagerFilePicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,32 @@ export class ExportManagerFilePicker implements IExportManagerFilePicker {
): Promise<Uri | undefined> {
// 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;

default:
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));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were looking for *.htm when the *.html file was created.
E.g. target = abc.htm, then the file created is abc.htm.html.

const options: SaveDialogOptions = {
defaultUri: dialogUri,
saveLabel: 'Export',
Expand Down
10 changes: 2 additions & 8 deletions src/client/datascience/export/exportUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {}
Expand Down Expand Up @@ -44,12 +43,7 @@ export class ExportUtil {
public async makeFileInDirectory(model: INotebookModel, fileName: string, dirPath: string): Promise<string> {
const newFilePath = path.join(dirPath, fileName);

try {
const content = model ? model.getContent() : '';
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

model cannot be undefined.

await this.fileSystem.writeFile(newFilePath, content, 'utf-8');
} catch (e) {
await this.errorHandler.handleError(e);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error handler was not rqeuired

}
await this.fileSystem.writeFile(newFilePath, model.getContent(), 'utf-8');

return newFilePath;
}
Expand Down