-
Notifications
You must be signed in to change notification settings - Fork 148
Defer positron-reticulate activation until needed
#13086
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -18,11 +18,6 @@ | |
| "lint": "eslint src --ext ts" | ||
| }, | ||
| "contributes": { | ||
| "languageRuntimes": [ | ||
| { | ||
| "languageId": "reticulate" | ||
| } | ||
| ], | ||
| "configuration": { | ||
| "type": "object", | ||
| "title": "%configurationTitle%", | ||
|
|
@@ -41,10 +36,6 @@ | |
| } | ||
| } | ||
| }, | ||
| "extensionDependencies": [ | ||
|
Contributor
Author
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. These forced the Python and R extensions to fully activate before reticulate's own |
||
| "ms-python.python", | ||
| "positron.positron-r" | ||
| ], | ||
| "devDependencies": { | ||
| "@types/glob": "^7.2.0", | ||
| "@types/mocha": "^9.1.0", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -386,7 +386,7 @@ class ReticulateRuntimeSession implements positron.LanguageRuntimeSession { | |
|
|
||
| private kernel: JupyterKernel | undefined; | ||
| public started = new Barrier(); | ||
| private pythonSession: positron.LanguageRuntimeSession; | ||
| private pythonSession!: positron.LanguageRuntimeSession; | ||
|
|
||
| // To create a reticulate runtime session we need to first create a python | ||
| // runtime session using the exported interface from the positron-python | ||
|
|
@@ -433,11 +433,11 @@ class ReticulateRuntimeSession implements positron.LanguageRuntimeSession { | |
| // Create the session itself. | ||
| const session = new ReticulateRuntimeSession( | ||
| rSession, | ||
| metadata, | ||
| sessionMetadata, | ||
| ReticulateRuntimeSessionType.Create, | ||
| progress | ||
| ); | ||
| await session.initializePythonSession(metadata); | ||
|
|
||
| return session; | ||
| } | ||
|
|
@@ -456,11 +456,11 @@ class ReticulateRuntimeSession implements positron.LanguageRuntimeSession { | |
| // Create the session itself. | ||
| const session = new ReticulateRuntimeSession( | ||
| rSession, | ||
| metadata, | ||
| sessionMetadata, | ||
| ReticulateRuntimeSessionType.Restore, | ||
| progress | ||
| ); | ||
| await session.initializePythonSession(metadata); | ||
|
|
||
| return session; | ||
| } | ||
|
|
@@ -620,15 +620,21 @@ class ReticulateRuntimeSession implements positron.LanguageRuntimeSession { | |
|
|
||
| constructor( | ||
| readonly rSession: positron.LanguageRuntimeSession, | ||
| runtimeMetadata: positron.LanguageRuntimeMetadata, | ||
| readonly sessionMetadata: positron.RuntimeSessionMetadata, | ||
| readonly sessionType: ReticulateRuntimeSessionType, | ||
| readonly progress: vscode.Progress<{ message?: string; increment?: number }> | ||
| ) { | ||
| this.onDidReceiveRuntimeMessage = this._messageEmitter.event; | ||
| this.onDidChangeRuntimeState = this._stateEmitter.event; | ||
| this.onDidEndSession = this._exitEmitter.event; | ||
| this.onDidUpdateResourceUsage = this._resourceUsageEmitter.event; | ||
| } | ||
|
|
||
| private async initializePythonSession(runtimeMetadata: positron.LanguageRuntimeMetadata): Promise<void> { | ||
|
Contributor
Author
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 is new, to split out the async work out of the |
||
| // When the kernelSpec is undefined, the PythonRuntimeSession | ||
| // will perform a restore session. | ||
| let kernelSpec: JupyterKernelSpec | undefined = undefined; | ||
| if (sessionType === ReticulateRuntimeSessionType.Create) { | ||
| if (this.sessionType === ReticulateRuntimeSessionType.Create) { | ||
| kernelSpec = { | ||
| 'argv': [], | ||
| 'display_name': "Reticulate Python Session", // eslint-disable-line | ||
|
|
@@ -651,16 +657,11 @@ class ReticulateRuntimeSession implements positron.LanguageRuntimeSession { | |
| }; | ||
| } | ||
|
|
||
| this.onDidReceiveRuntimeMessage = this._messageEmitter.event; | ||
| this.onDidChangeRuntimeState = this._stateEmitter.event; | ||
| this.onDidEndSession = this._exitEmitter.event; | ||
| this.onDidUpdateResourceUsage = this._resourceUsageEmitter.event; | ||
|
|
||
| this.progress.report({ increment: 10, message: vscode.l10n.t('Creating the Python session') }); | ||
|
|
||
| this.pythonSession = this.createPythonRuntimeSession( | ||
| this.pythonSession = await this.createPythonRuntimeSession( | ||
| runtimeMetadata, | ||
| sessionMetadata, | ||
| this.sessionMetadata, | ||
| kernelSpec | ||
| ); | ||
| } | ||
|
|
@@ -669,11 +670,14 @@ class ReticulateRuntimeSession implements positron.LanguageRuntimeSession { | |
| return this.pythonSession.getDynState(); | ||
| } | ||
|
|
||
| createPythonRuntimeSession(runtimeMetadata: positron.LanguageRuntimeMetadata, sessionMetadata: positron.RuntimeSessionMetadata, kernelSpec?: JupyterKernelSpec): positron.LanguageRuntimeSession { | ||
| async createPythonRuntimeSession(runtimeMetadata: positron.LanguageRuntimeMetadata, sessionMetadata: positron.RuntimeSessionMetadata, kernelSpec?: JupyterKernelSpec): Promise<positron.LanguageRuntimeSession> { | ||
|
Contributor
Author
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. We're making this async and explicitly await-ing |
||
| const api = vscode.extensions.getExtension('ms-python.python'); | ||
| if (!api) { | ||
| throw new Error(vscode.l10n.t('Failed to find the Python extension API.')); | ||
| } | ||
| if (!api.isActive) { | ||
| await api.activate(); | ||
| } | ||
|
|
||
| const pythonSession: positron.LanguageRuntimeSession = api.exports.positron.createPythonRuntimeSession( | ||
| runtimeMetadata, | ||
|
|
@@ -875,7 +879,7 @@ class ReticulateRuntimeSession implements positron.LanguageRuntimeSession { | |
| const metadata: positron.RuntimeSessionMetadata = { ...this.sessionMetadata, sessionId: `reticulate-python-${randomId}` }; | ||
|
|
||
| // When the R session is ready, we can start a new Reticulate session. | ||
| this.pythonSession = this.createPythonRuntimeSession( | ||
| this.pythonSession = await this.createPythonRuntimeSession( | ||
| this.runtimeMetadata, | ||
| metadata, | ||
| kernelSpec | ||
|
|
||
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.
This was the reason the extension was eagerly activated during
discoverAllRuntimes, but thelanguageId: "reticulate"anchor was a no-op (the actual runtime metadata registers underlanguageId: 'python').