From af1c020e8c2c7f0e2514b2d124aea20caca880d0 Mon Sep 17 00:00:00 2001 From: David Kutugata Date: Mon, 5 Apr 2021 15:08:26 -0700 Subject: [PATCH] Fix export to python script not appearing (#5407) * 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 --- .eslintrc.js | 1 - news/2 Fixes/5403.md | 1 + src/client/datascience/commands/exportCommands.ts | 13 +++++++++---- src/client/datascience/notebook/helpers/helpers.ts | 5 +++++ 4 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 news/2 Fixes/5403.md diff --git a/.eslintrc.js b/.eslintrc.js index 9499e220aac..b38516aeb79 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -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', diff --git a/news/2 Fixes/5403.md b/news/2 Fixes/5403.md new file mode 100644 index 00000000000..ab9c0130622 --- /dev/null +++ b/news/2 Fixes/5403.md @@ -0,0 +1 @@ +Fix for 'Export as Python Script' option not appearing. diff --git a/src/client/datascience/commands/exportCommands.ts b/src/client/datascience/commands/exportCommands.ts index 488ac8edada..036338fcdf7 100644 --- a/src/client/datascience/commands/exportCommands.ts +++ b/src/client/datascience/commands/exportCommands.ts @@ -127,7 +127,7 @@ 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, @@ -135,7 +135,12 @@ export class ExportCommands implements IDisposable { sendTelemetryEvent(Telemetry.ClickedExportNotebookAsQuickPick, undefined, { format: ExportFormat.python }); - this.commandManager.executeCommand(Commands.ExportAsPythonScript, contents, source, interpreter); + void this.commandManager.executeCommand( + Commands.ExportAsPythonScript, + contents, + source, + interpreter + ); } }); } @@ -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, @@ -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, diff --git a/src/client/datascience/notebook/helpers/helpers.ts b/src/client/datascience/notebook/helpers/helpers.ts index 211e15868db..aadaf5347a9 100644 --- a/src/client/datascience/notebook/helpers/helpers.ts +++ b/src/client/datascience/notebook/helpers/helpers.ts @@ -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; }