How to attach/set a kernel when opening a notebook with docmanager

Hi,

When I create a new notebook like so

const nbPanel: NotebookPanel = await app.commands.execute(
  'notebook:create-new',
  { kernelName: 'python3', activate: true }
);

I can then call nbPanel.revealed on it, which opens up the notebook with python3 selected as the kernel.

I’m trying to accomplish the same thing using DocumentManager’s open/openOrReveal methods.
Here, the file already exists and I want to just open it with a pre-defined kernel.

await app.commands.execute('docmanager:open', {
    path: 'Untitled.ipynb'
})

However this will open the file and asks the user to select a kernel:
image

I want to pre-set this so that the ‘python3’ kernel is automatically selected and attached to the notebook before opening it.

From the docs, here there is a parameter to pass in the kernel.

I’ve spent a lot of time trying to create a new python3 kernel and passing it in the parameter but to no avail, I’ve also tried to create a WidgetFactory and see if that could help but unfortunately hit a dead end.

Any advice on how I can accomplish this? :pensive:

After many many hours of scouring the documentation and github examples, I was able to figure this out thanks to a forum post on here. The solution was to simply past in the kernel name like so:

app.commands.execute('docmanager:open', {
    path: 'Untitled.ipynb',
    factory: "Notebook",
    kernel: { name: 'python3' }
})

The docs said to pass the kernel in as a kernel: Partial<IModel> which was quite confusing and unclear.

Now when the notebook is opened, the default kernel will be python3!