- Notifications
You must be signed in to change notification settings - Fork 1.3k
Refactor KernelSelection type to include a kind #13407
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
Conversation
Codecov Report
@@ Coverage Diff @@ ## master #13407 +/- ## ========================================== - Coverage 59.92% 59.90% -0.03% ========================================== Files 670 670 Lines 37203 37207 +4 Branches 5312 5311 -1 ========================================== - Hits 22294 22287 -7 - Misses 13772 13780 +8 - Partials 1137 1140 +3
Continue to review full report at Codecov.
|
| // If our new kernelspec has an interpreter, set that as our interpreter too | ||
| if (interpreter) { | ||
| this._executionInfo.interpreter = interpreter; | ||
| const metadata = { ...this._executionInfo.kernelSpec.metadata } || {}; |
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.
Not super happy about how this is implicit now. Although I guess it's no different than having it as a separate member.
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 agree.
We are already storing interpreter in the metadata in kernel spec.
Will ensure this is not written to disc
We just need a place to store the selection for the lifetime of the notebook.
The problem is trying to find a property where this can be stored. I cannot just add a property to keep track of this as we have a few different classes/layers and not sure where it needs to go. I feel its easier to stick it in here as this is tied directly to the notebook.
Anyways, a test is failing.
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 feel like this is a big change. I'm going to look, but I think that we have some code that assumes the kernelspecs with interpreter metadata in them are kernelspecs that we created off of an interpreter. This looks like it's now saving interpreter info in any kernelspec that we use.
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.
Something like this is now going to display the path of the interpreter not the path of the kernelspec, which I don't think we want.
| detail: pathUtils.getDisplayName(kernelSpec.metadata?.interpreter?.path || kernelSpec.path), |
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 should not have an effect on that.
We're only updating the metadata in the private copy.
Though I can see how this leads to a confusion.
As we're trying to clean up the whole KernelSelection stuff, I think this approach might not be the best.
However, this kernelspec is what is something that is shared across multiple classes and layers. And we need the corresponding interpreter information to be passed on.
Here's the explanation
- When we select a kernel, we also try to identify the best matching interpreter
- This is required to start a kernel from a Python interpreter
- The kernel spec is merely used to provide a name for the kernel and provide additional information such as env variables, startup CLI args.
- In light of the above, a kernel connection is NOT limited just to the following three:
- 1).
raw(start from executable) - 2).
kernelSpec - 3).
Live Kernel - Instead we have a 4rd option
- 4).
raw + kernelSpec
Based on our previous conversation this is no different from a kernelspec that has the python interpreter defined in theargvas the executable.
- 1).
I'll see what I can do to fix this up, moving back to draft.
@rchiodo @IanMatthewHuff
f691a49 to 6e4813b Compare | Kudos, SonarCloud Quality Gate passed!
|
| | { kernelModel: undefined; kernelSpec: undefined; interpreter: PythonInterpreter }; | ||
| | LiveKernelConnectionMetadata | ||
| | KernelSpecConnectionMetadata | ||
| | PythonKernelConnectionMetadata; |
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.
Here's the new type (3 of them for now):
- We have Kernel specs (starting kernels from a kernel spec JSON)
- Applies to both local and remote connections
- We have kernel models (live kernels) - connecting to existing kernels from Kernel Model
- Only applicable for remote connections
- We have Python Kernels
- We are either going to register the python interpreter as a kernel and start it (old jupyter)
- Or we start this using raw kernel approach.
I did not use the words raw as that is an implementation detail on how we start the kernel.
I.e. we could have a kernelSpec and we start that using Raw Kernels, e.g. python interpreter or .NET Executable could be defined as the first argument in argv of the kernelspec JSON file.
Hence we shouldn't really use the terms raw in the connection information.
I have left the commented code, as I will need to resolve this in the next PR
Basically we have other ways to connect to kernels
- E.g. we have a kernel spec and we don't have the python interpreter and we find one and use that
- Or we have a remote jupyter kernel spec and we need a python interpreter for that too (for intellisense, etc)
- Tomorrow we should be able to remove this easily
Todo:
- Rename
KernelSelectiontoKernelConnectionMetadata(its a big change, I didn't want that change to come in here else you might miss these subtle changes that are more important than a name change) - Refactor other parts to use this
- The last stage would be to clean up this type and use a single property if at all possible and remove the 3 properties (kernelModel, kernelSpec and interpreter) - though i fear we might end up with at most 2 in some cases)
- Either way, clean up slowly then the changes are clearer
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.
Thanks for removing raw. Seemed confusing as I knew there was a jupyter case that just had an interpreter in this type.
| | ||
| export interface IKernelSelectionListProvider { | ||
| getKernelSelections(resource: Resource, cancelToken?: CancellationToken): Promise<IKernelSpecQuickPickItem[]>; | ||
| export interface IKernelSelectionListProvider<T extends KernelSelection = KernelSelection> { |
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.
Using generics here, as that made the code simpler and obviously it is now strongly typed, hence found a few issues (deleted code that was not necessary).
| ); | ||
| }); | ||
| test('Should hide kernel from local sessions', async () => { | ||
| const kernelModels: LiveKernelModel[] = [ |
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.
When connecting to a local session, we cannot select a live kernel. Live kernels can only be picked when using remote sessions (even if the remote session is running on the local box)
| session, | ||
| cancelToken | ||
| ); | ||
| suggestions = suggestions.filter((item) => !this.kernelIdsToHide.has(item.selection.kernelModel?.id || '')); |
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 never going to happen, thanks to the strong typing found dead code.
| @IanMatthewHuff please re-review |
kind
For #13406
First refactor existing code to ensure we do not need the
interpreterproperty along withkernelspecs