jupytext
jupytext copied to clipboard
Make it easier to create text notebooks via the Launcher
I have a monorepo set up where several hundred contributors keep their py:percent formatted notebooks in version control, and where *.ipynb files are .gitignore'd. With our setup, users never intend to create .ipynb notebooks.
However, many users are having trouble remembering to use the "Python - Percent Format" button in the "Jupytext" section (which is currently at the very bottom of the Launcher) to create new notebooks. Instead they accidentally click one of the buttons in the "Notebook" section at the top of the Launcher, which ends up creating a new .ipynb notebook, which is the wrong thing to do:
So users have requested that the "Jupytext" section of the Launcher be moved to the top, ideally even replacing the "Notebook" section, to make this less error-prone for them. Unfortunately this is not currently possible.
Would you be willing to expose an option so folks like me could set up the Launcher to make it easier for our users to click the intended, Jupytext-based "new notebook" buttons from the Launcher?
Thanks for your consideration, and for the great work on Jupytext!
P.S. Another meaningful improvement would be to provide a dedicated "new notebook" button for each registered kernel in the Jupytext section, just like the "Notebook" and section offers for .ipynb notebooks (as well as the "Console" section). This way, users wouldn't have to later set the kernel for their new text notebook in a separate, follow-up step. But this is much lower priority than replacing the "Notebook" section (or at least moving the "Jupytext" section above it).
In the meantime, I've added this code to accomplish this from my own extension, in case it helps anyone else:
function fixJupytextIssue1344(app: JupyterFrontEnd) {
(app.shell as ILabShell).layoutModified.connect(() => {
const container = document.querySelector('.jp-Launcher-content');
if (!container) {
return;
}
const launcherSectionTitles = document.querySelectorAll('.jp-Launcher-sectionTitle');
const jupytextSection = findLauncherSectionWithTitle('Jupytext', launcherSectionTitles);
if (!jupytextSection) {
return;
}
container.prepend(jupytextSection);
findLauncherSectionWithTitle('Notebook', launcherSectionTitles)?.remove();
});
}
function findLauncherSectionWithTitle(title: string, els: NodeListOf<Element>) {
return Array.from(els)
.find(el => el.textContent?.trim() === title)
?.closest('.jp-Launcher-section');
}
Would you be willing to expose an option so folks like me could set up the Launcher to make it easier for our users to click the intended, Jupytext-based "new notebook" buttons from the Launcher?
Not sure what option are you referring here. The launcher-extension is the one that is responsible for arranging the icons and sections in launcher. Currently the order of sections is hard coded and not configurable. If you would like to make them configurable, you need to write your own launcher-extension and disable the default one.
It's up to you how far you're interested in going here, but the Jupytext users I support would be very happy to see Jupytext offering just a checkbox for "Hack the default launcher to replace the Notebook section with the Jupytext section (experimental)" that literally just ran the code I posted above. For whatever it's worth!
Since there's nothing like a picture to illustrate the difference, check out how much cleaner this looks and how much easier it is for users that never actually want to create .ipynb notebooks:
Hack the default launcher to replace the Notebook section with the Jupytext section (experimental)
I agree that it has an added value but it is a bit out of scope for Jupytext. It is also a question of maintainability. A better place to fix this is in upstream JupyterLab's launcher package and make the categories order configurable. The last time I spoke to JupyterLab maintainers they are open to this idea (see this issue and others referenced there). This will benefit not just Jupytext but to all the extensions that use Launcher icons. There are also custom launchers that can provide more configurability compared to vanilla launcher.
Thanks for the link to https://github.com/jupyterlab/jupyterlab/issues/12190 -- just liked and subscribed. Agreed that would be the "right" way to accomplish this. Still, that issue has been open for over 3 years and requires other people to do things. The stopgap I proposed above* would provide value to users in the meantime and doesn't require other projects to make changes, so I thought I'd just throw it out there.
* which would be clearly marked as "experimental" and could be removed once Jupytext is unblocked on taking a better approach
Thank you @ctcjab for sharing this interesting question and the code snippet! Great to see your enthusiastic use of text-only notebooks as well. Yes let's see if progress are made on the customisation of the launcher on the Jupyter end, thanks @mahendrapaipuri .