mwouts / jupytext

Jupyter Notebooks as Markdown Documents, Julia, Python or R scripts
https://jupytext.readthedocs.io
MIT License
6.6k stars 386 forks source link

Ability to specify jupytext as the viewer via URL #1211

Closed jabbera closed 7 months ago

jabbera commented 7 months ago

We send around alot of links like this to our jupyterhub instance: https://jupyterhubdev.private.tld/user-redirect/lab/tree/nfs-location/notebook.ipynb so people can open notebooks we consider common. They are sort of like complicated dashboards.

Jupytext support is exactly what we need to make these notebooks committed to source control more easily manageable.

However, I'm unable to find a query param or other URI modification I can add/do to the URL to tell jupyterlab to open in the Jupytext Notebook Viewer as opposed to whatever the user has configured for the default for .py files. IE something like:

https://jupyterhubdev.private.tld/user-redirect/lab/tree/nfs-location/notebook.py?renderer=Jupytext

or

https://jupyterhubdev.private.tld/user-redirect/lab/jupytext/nfs-location/notebook.py

If this isn't possible today can this be a requested feature?

mwouts commented 7 months ago

Hey @jabbera , thanks for reaching out!

I don't think this is possible at the moment (cc @mahendrapaipuri ?).

The closest that we can offer now is to setup Jupytext as the default viewer but you seem already aware of that option.

mahendrapaipuri commented 7 months ago

As @mwouts pointed out, currently, defaultViwers is JupyterLab native way of changing renderers. The defaultViewers config setting is exposed by DocumentManager extension and not Jupytext. So, we cannot really modify the setting using Jupytext extension (at least not in an elegant way).

If you are using JupyterHub, you have something like c.Spawner.default_url config where you can set it /lab/tree/nfs-location/notebook.py so when users are redirected to their Lab instances the notebooks will be opened in Jupytext format. Do you think that will work for you @jabbera ?

jabbera commented 7 months ago

@mahendrapaipuri I don't think that's exactly what I'm talking about. I can't change the default document viewer for all PY files. We have people who have their environment setup in very specific ways and I can't really mess with that. What I need is a way to tell JupyterLab to open a specific file in Jupytext via the URL. That way when we are sending out these dashboard links it doesn't matter how anyone has the document manager configured. Basically I need the Open in Jupytext context menu option triggerable via a query param or URL path modification.

mahendrapaipuri commented 7 months ago

Basically I need the Open in Jupytext context menu option triggerable via a query param or URL path modification.

I am afraid that this needs to be addressed with JupyterLab's docmanager-extension as it is responsible for opening files. Jupytext itself registers its file type Jupytext Notebook with that extension and does not control on how the file will be opened. Does it make sense?

jabbera commented 7 months ago

@mahendrapaipuri thanks! I'll follow up there.