Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix export to python script not appearing #5407

Merged
merged 4 commits into from
Apr 5, 2021
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
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)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like it won't work consistently. What line here is causing the notebook to not be python otherwise?

return true;
}

// Valid notebooks will have a language information in the metadata.
Copy link
Author

Choose a reason for hiding this comment

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

There's exceptions to this, sometime the kernelspec only has name and displayname

return kernelSpec?.language === PYTHON_LANGUAGE;
}
Expand Down