From 03d2e83250c86434811b5d2a5554aaf263464706 Mon Sep 17 00:00:00 2001 From: Cory Rivera Date: Wed, 6 Apr 2022 11:27:15 -0700 Subject: [PATCH] Treat Jupyter's Python 3 Ipykernel alias as Python 3. (#18943) --- src/sql/workbench/common/constants.ts | 1 + .../notebook/browser/models/notebookModel.ts | 24 ++++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/sql/workbench/common/constants.ts b/src/sql/workbench/common/constants.ts index b0515119a4..2ac4543c7d 100644 --- a/src/sql/workbench/common/constants.ts +++ b/src/sql/workbench/common/constants.ts @@ -36,6 +36,7 @@ export const FILE_QUERY_EDITOR_TYPEID = 'workbench.editorInput.fileQueryInput'; export const RESOURCE_VIEWER_TYPEID = 'workbench.editorInput.resourceViewerInput'; export const JUPYTER_PROVIDER_ID = 'jupyter'; +export const IPYKERNEL_DISPLAY_NAME = 'Python 3 (ipykernel)'; export const INTERACTIVE_PROVIDER_ID = 'dotnet-interactive'; export const INTERACTIVE_LANGUAGE_MODE = 'dib'; export const DEFAULT_NB_LANGUAGE_MODE = 'notebook'; diff --git a/src/sql/workbench/services/notebook/browser/models/notebookModel.ts b/src/sql/workbench/services/notebook/browser/models/notebookModel.ts index efa48cfd79..1cf6065e6c 100644 --- a/src/sql/workbench/services/notebook/browser/models/notebookModel.ts +++ b/src/sql/workbench/services/notebook/browser/models/notebookModel.ts @@ -39,6 +39,7 @@ import { AddCellEdit, CellOutputEdit, ConvertCellTypeEdit, DeleteCellEdit, MoveC import { IUndoRedoService } from 'vs/platform/undoRedo/common/undoRedo'; import { deepClone } from 'vs/base/common/objects'; import { DotnetInteractiveLabel } from 'sql/workbench/api/common/notebooks/notebookUtils'; +import { IPYKERNEL_DISPLAY_NAME } from 'sql/workbench/common/constants'; /* * Used to control whether a message in a dialog/wizard is displayed as an error, @@ -1345,19 +1346,20 @@ export class NotebookModel extends Disposable implements INotebookModel { private sanitizeSavedKernelInfo(): void { if (this._savedKernelInfo) { let displayName = this._savedKernelInfo.display_name; - - if (this._savedKernelInfo.display_name !== displayName) { - this._savedKernelInfo.display_name = displayName; - } let standardKernel = this._standardKernels.find(kernel => kernel.displayName === displayName || displayName.startsWith(kernel.displayName)); - if (standardKernel && this._savedKernelInfo.name && this._savedKernelInfo.name !== standardKernel.name) { - // Special case .NET Interactive kernel name to handle inconsistencies between notebook providers and jupyter kernel specs - if (this._savedKernelInfo.display_name === DotnetInteractiveLabel) { - this._savedKernelInfo.oldName = this._savedKernelInfo.name; - } + if (standardKernel) { + if (this._savedKernelInfo.name && this._savedKernelInfo.name !== standardKernel.name) { + // Special case .NET Interactive kernel name to handle inconsistencies between notebook providers and jupyter kernel specs + if (this._savedKernelInfo.display_name === DotnetInteractiveLabel) { + this._savedKernelInfo.oldName = this._savedKernelInfo.name; + } - this._savedKernelInfo.name = standardKernel.name; - this._savedKernelInfo.display_name = standardKernel.displayName; + this._savedKernelInfo.name = standardKernel.name; + this._savedKernelInfo.display_name = standardKernel.displayName; + } else if (displayName === IPYKERNEL_DISPLAY_NAME && this._savedKernelInfo.name === standardKernel.name) { + // Handle Jupyter alias for Python 3 kernel + this._savedKernelInfo.display_name = standardKernel.displayName; + } } } }