jupyter_server icon indicating copy to clipboard operation
jupyter_server copied to clipboard

Notebook Model Path contains UUID ?

Open Carreau opened this issue 3 years ago • 4 comments

Some time JPY_SESSION_NAME was introduce to less kernels know about which file they were attached to,

in particular this was set via

sm.create_session(
                    path=path, # where this is supposed to be the path of current document.
                    kernel_name=kernel_name,
                    kernel_id=kernel_id,
                    name=name,
                    type=mtype,
                )

Currently this seem to contain UUID, like I get sessions IDs that are like: 'path': 'tests/34361149-e3d8-4dbc-9302-0e86431b3e8c'.

Is that on purpose ?

Carreau avatar Nov 08 '22 15:11 Carreau

You can just test that with

import os
os.environ['JPY_SESSION_NAME']

In a python kernel.

Carreau avatar Nov 08 '22 15:11 Carreau

Interesting. I'm seeing the same thing, path is a straight UUID value (prefixed with any sub-directories under the root_dir). The server is receiving this value for path in the POST request for the SessionManager to start a kernel. Here's a screenshot from a debug session: image

Lab must be setting the filename to a UUID.

kevin-bates avatar Nov 08 '22 16:11 kevin-bates

Yes, JupyterLab first creates a session with a UUID as the path, then changes the name of the file to the notebook file. This was done as a workaround before we had pending kernels.

blink1073 avatar Nov 08 '22 16:11 blink1073

FWIW VS Code injects a __vsc_ipynb_file__ variable in the kernel (in globals()) which contains the path to the notebook:

 In:  __vsc_ipynb_file__
 Out: 'd:\\DataScience\\my_notebook.ipynb'

https://github.com/microsoft/vscode-jupyter/issues/8475

Maybe this should be coordinated across all notebook runners (JupyterLab, VS Code, PyCharm, ...)

2-5 avatar Dec 02 '22 14:12 2-5