Skip to content

Commit

Permalink
Fix export to python script not appearing (#5407)
Browse files Browse the repository at this point in the history
* assume a notebook is a python notebook if the
kernelspec name includes python

* news

* use intepreter to decide if its a python notebook

* keep both conditions
  • Loading branch information
David Kutugata authored Apr 5, 2021
1 parent f274dc1 commit af1c020
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,6 @@ module.exports = {
'src/client/datascience/editor-integration/codelensprovider.ts',
'src/client/datascience/editor-integration/cellhashprovider.ts',
'src/client/datascience/commands/commandLineSelector.ts',
'src/client/datascience/commands/exportCommands.ts',
'src/client/datascience/cellFactory.ts',
'src/client/datascience/notebook/notebookEditorCompatibilitySupport.ts',
'src/client/datascience/notebook/constants.ts',
Expand Down
1 change: 1 addition & 0 deletions news/2 Fixes/5403.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix for 'Export as Python Script' option not appearing.
13 changes: 9 additions & 4 deletions src/client/datascience/commands/exportCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,20 @@ export class ExportCommands implements IDisposable {
const items: IExportQuickPickItem[] = [];
const notebook = JSON.parse(contents) as nbformat.INotebookContent;

if (notebook.metadata && isPythonNotebook(notebook.metadata)) {
if (interpreter || (notebook.metadata && isPythonNotebook(notebook.metadata))) {
items.push({
label: DataScience.exportPythonQuickPickLabel(),
picked: true,
handler: () => {
sendTelemetryEvent(Telemetry.ClickedExportNotebookAsQuickPick, undefined, {
format: ExportFormat.python
});
this.commandManager.executeCommand(Commands.ExportAsPythonScript, contents, source, interpreter);
void this.commandManager.executeCommand(
Commands.ExportAsPythonScript,
contents,
source,
interpreter
);
}
});
}
Expand All @@ -149,7 +154,7 @@ export class ExportCommands implements IDisposable {
sendTelemetryEvent(Telemetry.ClickedExportNotebookAsQuickPick, undefined, {
format: ExportFormat.html
});
this.commandManager.executeCommand(
void this.commandManager.executeCommand(
Commands.ExportToHTML,
contents,
source,
Expand All @@ -165,7 +170,7 @@ export class ExportCommands implements IDisposable {
sendTelemetryEvent(Telemetry.ClickedExportNotebookAsQuickPick, undefined, {
format: ExportFormat.pdf
});
this.commandManager.executeCommand(
void this.commandManager.executeCommand(
Commands.ExportToPDF,
contents,
source,
Expand Down
5 changes: 5 additions & 0 deletions src/client/datascience/notebook/helpers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ export function isPythonNotebook(metadata?: nbformat.INotebookMetadata) {
if (metadata?.language_info?.name && metadata.language_info.name !== PYTHON_LANGUAGE) {
return false;
}

if (kernelSpec?.name.includes(PYTHON_LANGUAGE)) {
return true;
}

// Valid notebooks will have a language information in the metadata.
return kernelSpec?.language === PYTHON_LANGUAGE;
}
Expand Down

0 comments on commit af1c020

Please sign in to comment.