Skip to content
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

Add ability to restart kernel and run to current cell #6821

Closed
wants to merge 1 commit into from

Conversation

alesgenova
Copy link

References

Fixes #6746

Code changes

User-facing changes

A new entry is added to the "kernel" menu that reads "Restart Kkernel and Run up to Selected Cell".
Upon clicking, the kernel will be restarted, and all the cells above the current selection (and the current selection itself) will be run.

Before:
Screenshot_2019-07-13 JupyterLab(1)

After:
Screenshot_2019-07-13 JupyterLab

Backwards-incompatible changes

@jupyterlab-dev-mode
Copy link

Thanks for making a pull request to JupyterLab!

To try out this branch on binder, follow this link: Binder

Copy link
Member

@ian-r-rose ian-r-rose left a comment

Choose a reason for hiding this comment

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

Thanks @alesgenova, this is a really nice piece of work, and I think it's a useful option to have in the menu. One concern that I have is this: the mainmenu "semantic" commands are pretty specialized, and designed to be commands that are useful to more than one type of activity. So, "Restart and Run All" is, for instance, used by both the notebook and the text editor.

In this case, I think the command in question may be more relevant to just the notebook. In that case, we would want to implement the command similarly to how the "Run All Above" and "Run All Below" commands are implemented here:

commands.addCommand(CommandIDs.runAllAbove, {
label: 'Run All Above Selected Cell',
execute: args => {
const current = getCurrent(args);
if (current) {
const { context, content } = current;
return NotebookActions.runAllAbove(content, context.session);
}
},
isEnabled: () => {
// Can't run above if there are multiple cells selected,
// or if we are at the top of the notebook.
return (
isEnabledAndSingleSelected() &&
tracker.currentWidget.content.activeCellIndex !== 0
);
}
});
commands.addCommand(CommandIDs.runAllBelow, {
label: 'Run Selected Cell and All Below',
execute: args => {
const current = getCurrent(args);
if (current) {
const { context, content } = current;
return NotebookActions.runAllBelow(content, context.session);
}
},
isEnabled: () => {
// Can't run below if there are multiple cells selected,
// or if we are at the bottom of the notebook.
return (
isEnabledAndSingleSelected() &&
tracker.currentWidget.content.activeCellIndex !==
tracker.currentWidget.content.widgets.length - 1
);
}
});

So it would be added as a more normal menu item, rather than using the specialized ICodeRunner interface. There is some more documentation discussing the differences between these approaches here

Alternatively, if we decide that this is appropriate for a semantic menu item, we would want to abstract it a bit further with a noun for the thing-to-run (similar to how the "Run All" commands work above). Then it could interpolate the right noun for things that don't have cells to run.

What do you think @alesgenova?

@jasongrout jasongrout self-requested a review July 29, 2019 20:13
@jasongrout
Copy link
Contributor

@alesgenova - thanks again! What do you think of @ian-r-rose's comments above?

@jasongrout jasongrout added this to the Future milestone Sep 9, 2019
@vidartf
Copy link
Member

vidartf commented Oct 21, 2019

@ian-r-rose I think we can consider this a fire and forget PR. Do you think this should be merged as is, or should it not be merged in its current state?

@alesgenova
Copy link
Author

I'm sorry for the delay in fixing the review comments, it's been hard to find the motivation to sit down and code during the sunny summer weekends.

In case you don't want to merge it as is, I promise I'll find some time to address the problems during the upcoming cold weather in upstate NY!

@tgeorgeux
Copy link
Contributor

@alesgenova Just checking in on this. I may have the opportunity to have to get some help on this from our intern team at Cal Poly. But I wanted to check in with you first. Would you like help on finishing this off or would you prefer to leave it for you?

@alesgenova
Copy link
Author

@tgeorgeux I have been traveling and haven't had a chance to get back to this yet.
Please, feel free to complete the feature properly :)

@alesgenova
Copy link
Author

Closing, since the feature has been implemented in #7789

@alesgenova alesgenova closed this Jan 17, 2020
@lock lock bot added the status:resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion. label Feb 16, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Feb 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement pkg:mainmenu pkg:notebook status:resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion. tag:Design and UX
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Restart and run to current cell
5 participants