-
Notifications
You must be signed in to change notification settings - Fork 386
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
opening jupytext notebooks in jlab #803
Comments
Hi @parmentelat , well these two issues have been there for a while, cf #271 for instance. But sure I'll be happy to give another try to get them fixed. For the first point, i.e. the default viewer for I understand that the second item is a bigger problem. I remember discussing with @jasongrout how to change the default viewer for the |
For me, changing the document user settings does not seem to change the default viewer for |
Was wanting to set the notebook viewer as the default for python also. Having poked around in the jupyterlab code, looks like there are a few ways forward. The problem is that jupytext isn't registering as a widget factory and the notebook viewer doesn't explicitly support python/markdown/whatever files (my understanding of jupyter/jupytext internals is pretty rough, but I am a software engineer). Looks like when a viewer is configured in the setting, it's then trying to map that to the viewer. This is the CR that added the ability to specify a widget to viewer mapping: Using this registry of viewer factories: The Notebook viewer registers a limited number of file extensions (and I think mime types). It's not possible to add a new type to an existing viewer (ie add python to the notebook viewer) according to this issue: That issue proposes mapping mime types to viewers, also not currently done. The way I see it, there are a few options to enable the desired behavior.
Option 2 would probably be quickest, but a bit of a hack. Option 1 would likely be preferable long term. The code for the notebook viewer (as an extension) is this I believe: https://github.com/jupyterlab/jupyterlab/tree/997f3af68396539136ab0cb8512c73c07e021e4a/packages/notebook-extension And I think it's the widget factory stuff that would need modifying, ie use a different factory name. That's as far as I got. I'll probably look a bit more at some point, but I'm a little busy. Any pointers welcome. |
This is confusing, so I figured I'd gather a few links to other discussions in one place. Looks like there's a difference between how links are handled and opening from a file browser (I think, need to read a bit more of this) A fairly equivalent discussion for markdown This is a bit of a bodge that adds the option to the 'open with' menu, a similar hack could probably also be added when setting defaults (not ideal): https://github.com/jupyterlab/jupyterlab/pull/5247/files |
Thanks to @fcollonval 's contribution #877 we can now:
This new option will be made available with Jupytext 1.13.2 (soon on pip), so I will close this issue (comments are welcome and a confirmation that this also works for people here would be great!) Note: the question of opening links to |
Trying to reproduce this for some MyST notebooks, but I can't seem to be able to make it work poliastro/poliastro#1410 I changed |
@mwouts from the comment of @astrojuanlu I realize that Jupytext is handling on the server side lots of file extensions than the one appearing for now in the labextension (for instance the one of MyST notebooks). To support them with the one-click feature, they need to be listed as supported extension by the new file type jupytext/packages/labextension/src/index.ts Line 431 in 6fee30c
I let you (or someone with a better knowledge of the supported format) update that list as needed to match the supported extensions. |
I see! Sure I'll do that, I will try to find some time to fix that tonight... Thanks for the pointers! |
Well... @astrojuanlu , which extension do you use for the MyST format? If you use the
At least it works on Binder with the current version, see this example: https://mybinder.org/v2/gh/mwouts/jupytext/main?urlpath=lab/tree/demo/World population.myst.md Of course I can add the |
I'm currently using |
Thanks @astrojuanlu for the details, now I'm sure there is at least one user for them so I am willing to add these extensions to the file type 😄 But maybe that is also the opportunity to create a few more file types? @chrisjsewell , @jjallaire, what would you think of replacing jupytext/packages/labextension/src/index.ts Lines 426 to 433 in 002fa06
with three file types, as follows:
(@fcollonval , are we allowed to use spaces in file types?) |
Yes, that sounds good to me! |
I don't know of any example. But I think it is find. One comment of creating multiple file types, a file type determines what viewer can be used for it - and some styling in the file browser (like the file icons - that get override by Jupytext anyway). So I would recommend being careful about adding many of them, especially if a classical pattern for a user is then to override the default viewer for all of them. But this is possible, see the image viewer for example: |
thanks @fcollonval! |
If the default viewer is then changed to the new "Jupytext Notebook", yes it will directly open with the notebook viewer.
|
I am experimenting with something like this: 73ddc83 However this only works for the file types that are lower case ( So I'm going to try with lower case file types now 😄 |
With b8ee502 it works much better: I also note that opening the |
A quick wrap-up... I have a PR at #882 that seems to work well. The new settings look like this: {
"defaultViewers": {
"markdown": "Jupytext Notebook",
"myst": "Jupytext Notebook",
"r-markdown": "Jupytext Notebook",
"quarto": "Jupytext Notebook",
"julia": "Jupytext Notebook",
"python": "Jupytext Notebook",
"r": "Jupytext Notebook"
}
} and the users can choose the subset that matches their preference. The @fcollonval , I have seen your advice about not creating too many file types - I believe this setting is a bit more appropriate because we're talking of different document types here (and even different user clusters probably). Also I have added the @chrisjsewell , @jjallaire , in the end I had to change the file types names (lower case, no space), are you OK with the new names: |
Yes lower-case fine by me! |
yeh no worries |
The new version @astrojuanlu , @parmentelat , please let us know if it works according to your expectations ! Please remember that you need to override the default settings for the "Document Manager" section with (a subset) of {
"defaultViewers": {
"markdown": "Jupytext Notebook",
"myst": "Jupytext Notebook",
"r-markdown": "Jupytext Notebook",
"quarto": "Jupytext Notebook",
"julia": "Jupytext Notebook",
"python": "Jupytext Notebook",
"r": "Jupytext Notebook"
}
} You can also use a local default_setting_overrides.json file as we do on Binder, maybe we could add a mention of that in the documentation... |
Hi @mwouts I have
with that in place
so yes, it's definitely much better ! and many thanks @mwouts for all the hard work :) this will indeed help moving infrastructure tools towards jlab but I just wanted to add however that it's a little bit of a pity that an extra configuration step is required here |
Thank you @parmentelat ! And actually the credit is for @fcollonval who unblocked this subject, and also addressed the other one about links in notebooks (#271, should be fixed with Jupyter Lab 4.0)
Sure I understand. We chatted about that with @fcollonval , and I was the one who asked for not changing the default configuration, at least for now, because I did not want to surprise all users with this. My experience with Jupyter Notebook was that a few people did not like the new default for Maybe we can consider changing the default in a future (non-minor) version of Jupytext, or even maybe another option would be to create another package that will just install this configuration file? What do you think? |
As the override json file could be set/modify by the user or an system administrator. I advice not going that path. One possibility would be to provide in the other package, a tiny JupyterLab extension that override the default factory. Or to prompt the user if he wants to change the default viewer if he used the open with editor. |
The new config does work as expected, thanks a lot! |
@fcollonval seems to warn us against that idea; I don't care much about how exactly this happens, what really matters to me is that
now again, all this is to help us lead students towards using |
Good news, with the newly released JupyterLab server 2.9.0 this could be a thing using the new |
Hiya
trying to migrate from classic to something more modern, I'm facing an issue that has to do with the awkward path that seems to be the only way to open a jupytext notebook under jlab
foo.md
in the file browser results in a markdown editor; I need to do right-click → open with → Notebook to get it to open as a notebooklab/tree/path/foo.md
has the same result as from the UI, so I can't seem to find any way to open it as a notebook from a URLthe first issue is an impediment but of course something I can live with; the second is more of a showstopper for me at this point
I'd love to find a way around this
ps
for reference, I've be stirring this in a couple other threads already
https://discourse.jupyter.org/c/jupyterlab/17
and more marginally in
jupyterlab/retrolab#162
in the latter @jtpio suggested that an extension could come in handy, but I must honestly admit that the whole jlab extension ecosystem has scared the hell out of me a bit, so I am unsure what this would actually involve..
The text was updated successfully, but these errors were encountered: