Skip to content

Allow opening notebooks without starting a kernel#17798

Merged
krassowski merged 8 commits into
jupyterlab:mainfrom
jtpio:open-no-kernel
Aug 21, 2025
Merged

Allow opening notebooks without starting a kernel#17798
krassowski merged 8 commits into
jupyterlab:mainfrom
jtpio:open-no-kernel

Conversation

@jtpio

@jtpio jtpio commented Aug 19, 2025

Copy link
Copy Markdown
Member

References

Fixes #4040

Related issue in Notebook: jupyter/notebook#3170

The factory approach mentioned in #12019 sounded like a good start, but it also brought a couple of challenges as mentioned in this comment: #12019 (comment).
So this PR takes a different approach by defining a command and putting it in the context menu instead of trying to define a new notebook factory.

Currently, this is specific to the notebook only, but I wanted to open the PR early to get an idea of what people thought about this approach before trying to generalize these to other types of documents that can be backed by a kernel (which could likely be done in a follow-up PR).

Code changes

  • Allow providing kernelPreference?: ISessionContext.IKernelPreference when opening a document
  • Add a new command to open a notebook without a kernel, from the "Open With" context menu
  • UI tests

User-facing changes

jupyterlab-notebook-no-kernel.mp4

Backwards-incompatible changes

None

@jupyterlab-probot

Copy link
Copy Markdown

Thanks for making a pull request to jupyterlab!
To try out this branch on binder, follow this link: Binder

@jtpio

jtpio commented Aug 19, 2025

Copy link
Copy Markdown
Member Author

Since CI is passing, I'll mark the PR as ready for review, so folks can try it locally or on Binder: https://mybinder.org/v2/gh/jtpio/jupyterlab/open-no-kernel?urlpath=lab

Happy to hear what people think and iterate more on it if needed.

@jtpio jtpio marked this pull request as ready for review August 19, 2025 07:36
Comment on lines +1168 to +1177
const hasNotebooks = selectedItems.some(item => item.type === 'notebook');

if (hasNotebooks) {
items.push(
openWith.addItem({
args: {},
command: CommandIDs.openNotebookNoKernel
})
);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about not adding a new command and just reusing the existing open command and passing the kernelPreference argument to it? This would require changing .some to .every but this aligns with how it is done already:

// get the widget factories that could be used to open all of the items
// in the current filebrowser selection
const factories = tracker.currentWidget
? Private.OpenWith.intersection<DocumentRegistry.WidgetFactory>(
map(tracker.currentWidget.selectedItems(), i => {
return Private.OpenWith.getFactories(docRegistry, i);
})
)
: new Set<DocumentRegistry.WidgetFactory>();
// make new menu items from the widget factories
items = [...factories].map(factory =>
openWith.addItem({
args: { factory: factory.name, label: factory.label || factory.name },
command: CommandIDs.open
})
);
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me check, looks like we will need to use the filebrowser:open command to be able to handle multiple selections, and also pass the kernelPreference around to that command and to docmanager:open too.

@krassowski krassowski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @jtpio - two minor suggestions.

Comment thread packages/notebook-extension/src/index.ts Outdated
Comment thread packages/docmanager-extension/src/index.tsx Outdated
jtpio and others added 5 commits August 20, 2025 13:08
Co-authored-by: Michał Krassowski <5832902+krassowski@users.noreply.github.com>
Co-authored-by: Michał Krassowski <5832902+krassowski@users.noreply.github.com>
@jtpio

jtpio commented Aug 20, 2025

Copy link
Copy Markdown
Member Author

@krassowski krassowski merged commit 133aaa0 into jupyterlab:main Aug 21, 2025
83 checks passed
@jtpio jtpio deleted the open-no-kernel branch August 21, 2025 08:28
@jasongrout

Copy link
Copy Markdown
Contributor

I wrote up a few thoughts about this general approach at #18343, and proposed a way to make customizing the kernel startup behavior more institutional.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Open existing Notebook without kernel

3 participants