Hiya all
I’m working on the jlab4 extension for jupytext
I’m almost there, except for the toolbar that (most of the time) fails to show up, and so I’m getting this:
a regular ipynb notebook on top, and a jupytext notebook below
I could use some help with that; I have tracked this down in this issue
opened 10:16AM - 20 Jul 23 UTC
this is a followup on https://github.com/mwouts/jupytext/pull/1092
As planned… I have made manual tests of the tentative jupyterlab extension as packaged in version
1.15.0.dev1
## test env
create a fresh conda env
```bash
conda create -y -n nb7-text python=3.11
conda activate nb7-text
pip install notebook; pip install --pre jupytext
```
as of today this gives me
```bash
pip freeze | egrep 'notebook|jupyte'
jupyter-events==0.6.3
jupyter-lsp==2.2.0
jupyter_client==8.3.0
jupyter_core==5.3.1
jupyter_server==2.7.0
jupyter_server_terminals==0.4.4
jupyterlab==4.0.3
jupyterlab-pygments==0.2.2
jupyterlab_server==2.23.0
jupytext==1.15.0.dev1
notebook==7.0.0
notebook_shim==0.2.3
```
## test scenario
I have 2 notebooks with identical contents, one in `ipynb` and one in `py:percent` format
* open them both under notebook
* open them both under jlab (`jupyterlab` gets installed implicitly as a dependency of `notebook` as of nb7)
## observations
as of today, I have observed that in both notebook and jupyterlab, the jupytext format leads to a UI with a missing toolbar (see pictures below)
### notebook
![jupytext-notebook-OK-ipynb](https://github.com/mwouts/jupytext/assets/4519227/f0df5c14-b484-4420-a1e2-ddf83cdd0db8)
but
![jupytext-notebook-KO-py](https://github.com/mwouts/jupytext/assets/4519227/8003f8f5-5a3f-496e-9c1d-e78a6130e6ed)
### jupyterlab
same symptom, more or less
![jupytext-lab](https://github.com/mwouts/jupytext/assets/4519227/00a67297-9b76-43ae-8644-a7757b1d0534)
## troubleshooting
in both cases I see these messages that I do not like at all:
### notebook
![jupytext-notebook-KO-py-console-warnings](https://github.com/mwouts/jupytext/assets/4519227/dc7fc930-a538-4d60-b0f4-d2083fa3d897)
### jlab
![jupytext-lab-console-warnings](https://github.com/mwouts/jupytext/assets/4519227/1a1e7f5a-7428-419b-98d2-f3403d3f46c9)
**EDIT**
## conjecture
the following conjecture has been proven false - see below
~~I am starting to wonder if that idea of shipping a single extension for both jlab3 and jlab4 has any chance to fly; it feels like the extension, as compiled under jlab3, has pinned versions of some modules, but that these modules are loaded under another version number, and the loader refuses to load several instances (that's what *singleton* suggests. right?)~~
~~it's ironic because the missing area is not something that jupytext tampers with at all; I wonder why these modules are even needed ?~~
and it appears the culprit may be the way we create the NotebookWidgetFactory
in https://github.com/mwouts/jupytext/blob/6747cd6abe61b52ba8bd87ec0b374160f50e4b04/packages/labextension/src/index.ts#L510
(in any case notebookFactory.toolbarFactory
is always undefined
)
so I guess the short version is, what is the right way for this extension - which primarily wants to mimick the usual notebook widget - to initialize its toolbar so it gets just the same as if it were a regular notebook widget
I might be able to make deeper progress on this if I was able to debug the jupyterlab code - like, setting breakpoints - but my skills are limited here, so any hint in that direction would be helpful as well
thanks in advance
Hey @parmentelat
There is no more default notebook toolbar factory as it can be customized through the settings.
To build the toolbar for Jupytext, I guess you can re-use the same parameters as the on for the notebook widget factory; see
settings.dispose();
});
});
return indicator;
}
);
if (settingRegistry) {
// Create the factory
toolbarFactory = createToolbarFactory(
toolbarRegistry,
settingRegistry,
FACTORY,
PANEL_SETTINGS,
translator
);
}
const trans = translator.load('jupyterlab');
See also the documentation: Common Extension Points — JupyterLab 4.0.3 documentation
1 Like
thanks for the feedback!
I’ve come up with this:
// the way to create the toolbar factory is different in JupyterLab 3 and 4
let toolbarFactory
if (! JLAB4) {
toolbarFactory = notebookFactory.toolbarFactory
} else {
// primarily this block is copied/pasted from jlab4 code and specifically
// jupyterlab/packages/notebook-extension/src/index.ts
// inside the function `activateWidgetFactory` at line 1150 as of this writing
//
const FACTORY = 'Notebook';
const PANEL_SETTINGS = '@jupyterlab/notebook-extension:panel';
toolbarFactory = createToolbarFactory(
toolbarRegistry,
settingRegistry,
FACTORY,
PANEL_SETTINGS,
translator
)
}
this is part of restore notebook toolbar under jlab4 - fix for issue #1107 by parmentelat · Pull Request #1109 · mwouts/jupytext · GitHub
@fcollonval would you care to do a quick review ?
it almost works fine, except for one corner case: if I pour into the mix an extension that adds buttons in the toolbar, then the added buttons do not show up, in general, in the Jupytext Notebook widget (they do show up but only in widgets that are restored as part of the workspace restoration)
in any case this is already much better, so many thanks @fcollonval for pointing me in the right direction