-
Notifications
You must be signed in to change notification settings - Fork 289
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
Separate Jupyter session creator for raw and Jupyter #13439
Merged
DonJayamanne
merged 6 commits into
main
from
separateJupyterSessionCreatorForRawAndJupyter
May 2, 2023
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
90b1168
Separate raw kernel session creator from Jupyter
DonJayamanne 65dca56
wip
DonJayamanne 8ccd66c
fix formatting
DonJayamanne d0548ee
wip
DonJayamanne 5e39ad2
wip
DonJayamanne cd8babf
Remove redundant abstract class
DonJayamanne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import { inject, injectable, optional } from 'inversify'; | ||
import { IPythonExtensionChecker } from '../../../platform/api/types'; | ||
import { ConnectNotebookProviderOptions, IJupyterConnection, IJupyterServerConnector } from '../../types'; | ||
import { DisplayOptions } from '../../displayOptions'; | ||
import { IRawKernelConnectionSessionCreator } from '../../raw/types'; | ||
import { IJupyterNotebookProvider } from '../types'; | ||
import { PythonExtensionNotInstalledError } from '../../../platform/errors/pythonExtNotInstalledError'; | ||
|
||
@injectable() | ||
export class JupyterServerConnector implements IJupyterServerConnector { | ||
private readonly startupUi = new DisplayOptions(true); | ||
constructor( | ||
@inject(IRawKernelConnectionSessionCreator) | ||
@optional() | ||
private readonly rawSessionCreator: IRawKernelConnectionSessionCreator | undefined, | ||
@inject(IJupyterNotebookProvider) | ||
private readonly jupyterNotebookProvider: IJupyterNotebookProvider, | ||
@inject(IPythonExtensionChecker) private readonly extensionChecker: IPythonExtensionChecker | ||
) {} | ||
|
||
public async connect(options: ConnectNotebookProviderOptions): Promise<IJupyterConnection> { | ||
if (!options.ui.disableUI) { | ||
this.startupUi.disableUI = false; | ||
} | ||
const handler = options.ui.onDidChangeDisableUI(() => { | ||
if (!options.ui.disableUI) { | ||
this.startupUi.disableUI = false; | ||
handler.dispose(); | ||
} | ||
}); | ||
options.ui = this.startupUi; | ||
if (this.rawSessionCreator?.isSupported && options.localJupyter) { | ||
throw new Error('Connect method should not be invoked for local Connections when Raw is supported'); | ||
} else if (this.extensionChecker.isPythonExtensionInstalled || !options.localJupyter) { | ||
return this.jupyterNotebookProvider.connect(options).finally(() => handler.dispose()); | ||
} else { | ||
handler.dispose(); | ||
if (!this.startupUi.disableUI && options.localJupyter) { | ||
await this.extensionChecker.showPythonExtensionInstallRequiredPrompt(); | ||
} | ||
throw new PythonExtensionNotInstalledError(); | ||
} | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/kernels/jupyter/launcher/kernelConnectionSessionCreator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import { inject, injectable, optional } from 'inversify'; | ||
import { | ||
GetServerOptions, | ||
IKernelConnectionSession, | ||
IKernelConnectionSessionCreator, | ||
isLocalConnection, | ||
NotebookCreationOptions | ||
} from '../../types'; | ||
import { Cancellation } from '../../../platform/common/cancellation'; | ||
import { IRawKernelConnectionSessionCreator } from '../../raw/types'; | ||
import { IJupyterNotebookProvider } from '../types'; | ||
|
||
/** | ||
* Generic class for connecting to a server. Probably could be renamed as it doesn't provide notebooks, but rather connections. | ||
*/ | ||
@injectable() | ||
export class KernelConnectionSessionCreator implements IKernelConnectionSessionCreator { | ||
constructor( | ||
@inject(IRawKernelConnectionSessionCreator) | ||
@optional() | ||
private readonly rawKernelSessionCreator: IRawKernelConnectionSessionCreator | undefined, | ||
@inject(IJupyterNotebookProvider) | ||
private readonly jupyterNotebookProvider: IJupyterNotebookProvider | ||
) {} | ||
|
||
public async create(options: NotebookCreationOptions): Promise<IKernelConnectionSession> { | ||
const kernelConnection = options.kernelConnection; | ||
const isLocal = isLocalConnection(kernelConnection); | ||
|
||
if (this.rawKernelSessionCreator?.isSupported && isLocal) { | ||
return this.rawKernelSessionCreator.create( | ||
options.resource, | ||
options.kernelConnection, | ||
options.ui, | ||
options.token | ||
); | ||
} | ||
const serverOptions: GetServerOptions = isLocal | ||
? { | ||
resource: options.resource, | ||
token: options.token, | ||
ui: options.ui, | ||
localJupyter: true | ||
} | ||
: { | ||
resource: options.resource, | ||
token: options.token, | ||
ui: options.ui, | ||
localJupyter: false, | ||
serverId: kernelConnection.serverId | ||
}; | ||
await this.jupyterNotebookProvider.connect(serverOptions); | ||
Cancellation.throwIfCanceled(options.token); | ||
|
||
return this.jupyterNotebookProvider.createNotebook(options); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
These are not the final names and final classes, the primary goal is to break down larger components into smaller ones , this way re-factoring this would be simpler and its easier
Right now there's a lot of inheritance and coupling