-
Notifications
You must be signed in to change notification settings - Fork 294
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
No prompt to install Python when open an exist nb without Kernel #5202
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,11 +107,8 @@ export function isPythonNotebook(metadata?: nbformat.INotebookMetadata) { | |
if (metadata?.language_info?.name && metadata.language_info.name !== PYTHON_LANGUAGE) { | ||
return false; | ||
} | ||
if (kernelSpec?.language && kernelSpec.language !== PYTHON_LANGUAGE) { | ||
return false; | ||
} | ||
// All other notebooks are python notebooks. | ||
return true; | ||
// Valid notebooks will have a language information in the metadata. | ||
return kernelSpec?.language === PYTHON_LANGUAGE; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This too wasn't right, better now |
||
} | ||
/** | ||
* No need to update the notebook metadata just yet. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
|
||
// eslint-disable-next-line @typescript-eslint/no-require-imports | ||
import { join } from 'path'; | ||
import { Uri, NotebookCell, NotebookDocument, NotebookKernel as VSCNotebookKernel } from 'vscode'; | ||
import { Uri, NotebookCell, NotebookDocument, NotebookKernel as VSCNotebookKernel, notebook } from 'vscode'; | ||
import { ICommandManager, IVSCodeNotebook } from '../../common/application/types'; | ||
import { disposeAllDisposables } from '../../common/helpers'; | ||
import { traceInfo } from '../../common/logger'; | ||
|
@@ -16,6 +16,7 @@ import { KernelSocketInformation } from '../types'; | |
import { traceCellMessage, trackKernelInfoInNotebookMetadata } from './helpers/helpers'; | ||
|
||
export class VSCodeNotebookKernelMetadata implements VSCNotebookKernel { | ||
private notebookKernels = new WeakMap<NotebookDocument, IKernel>(); | ||
get preloads(): Uri[] { | ||
return [ | ||
Uri.file(join(this.context.extensionPath, 'out', 'ipywidgets', 'dist', 'ipywidgets.js')), | ||
|
@@ -64,18 +65,29 @@ export class VSCodeNotebookKernelMetadata implements VSCNotebookKernel { | |
this.commandManager.executeCommand(Commands.NotebookEditorInterruptKernel).then(noop, noop); | ||
} | ||
private updateKernelInfoInNotebookWhenAvailable(kernel: IKernel, doc: NotebookDocument) { | ||
if (this.notebookKernels.get(doc) === kernel) { | ||
return; | ||
} | ||
this.notebookKernels.set(doc, kernel); | ||
let kernelSocket: KernelSocketInformation | undefined; | ||
const handlerDisposables: IDisposable[] = []; | ||
|
||
// If the notebook is closed, dispose everything. | ||
notebook.onDidCloseNotebookDocument( | ||
(e) => { | ||
if (e === doc) { | ||
disposeAllDisposables(handlerDisposables); | ||
} | ||
}, | ||
this, | ||
handlerDisposables | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better clean up of handlers. |
||
); | ||
const saveKernelInfo = () => { | ||
const kernelId = kernelSocket?.options.id; | ||
if (!kernelId) { | ||
return; | ||
} | ||
traceInfo(`Updating preferred kernel for remote notebook ${kernelId}`); | ||
this.preferredRemoteKernelIdProvider.storePreferredRemoteKernelId(doc.uri, kernelId).catch(noop); | ||
|
||
disposeAllDisposables(handlerDisposables); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was wrong |
||
}; | ||
|
||
const kernelDisposedDisposable = kernel.onDisposed(() => disposeAllDisposables(handlerDisposables)); | ||
|
@@ -92,8 +104,14 @@ export class VSCodeNotebookKernelMetadata implements VSCNotebookKernel { | |
return; | ||
} | ||
trackKernelInfoInNotebookMetadata(doc, kernel.info); | ||
if (kernel.info.status === 'ok' && this.selection.kind === 'startUsingKernelSpec') { | ||
saveKernelInfo(); | ||
if (this.selection.kind === 'startUsingKernelSpec') { | ||
if (kernel.info.status === 'ok') { | ||
saveKernelInfo(); | ||
} else { | ||
disposeAllDisposables(handlerDisposables); | ||
} | ||
} else { | ||
disposeAllDisposables(handlerDisposables); | ||
} | ||
}); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,15 +83,12 @@ export class VSCodeNotebookModel extends BaseNotebookModel { | |
return this.document ? this.document.cells.length : this.notebookJson.cells?.length ?? 0; | ||
} | ||
public getNotebookData() { | ||
if (!this.preferredLanguage) { | ||
throw new Error('Preferred Language not initialized'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its possible to not have a preferred langauge, we'll default to plain text. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: When you create a blank notebook and we return cells with plain text, Tha'ts existing fucntionality. I.e. if you create a blank notebook and cells are TypeScript, then select Juali kernel, then language of empty cells in blank notebook will change to Julia. |
||
} | ||
return notebookModelToVSCNotebookData( | ||
this.isTrusted, | ||
this.notebookContentWithoutCells, | ||
this.file, | ||
this.notebookJson.cells || [], | ||
this.preferredLanguage, | ||
this.preferredLanguage || 'plaintext', | ||
this.originalJson | ||
); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this wasn't right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If user doesn't have a python kernel at all, no point defaulting to Python
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Else later if you save these notebooks and open it, then we assume its a python notebook and ask the user to install Python.