jtpio / ipylab

Control JupyterLab from Python Notebooks with Jupyter Widgets 🧪 ☢️ 🐍

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exposing current `sessionContext` to ipylab

TK-21st opened this issue · comments

General Description

Add API to ipylab where the user can gather information about the current or all sessionContext currently in the JLab workspace (potentially exposing sessionManager).

Usage

ipylab currently supports command execution such as

from ipylab import JupyterFrontEnd
app = JupyterFrontEnd()
opts = {}
# create new console with no options
app.commands.execute('console:create', opts)

For JupyterLab extensions that interacts with kernel sessions via sessionContext, we should be able to have access to the current session in the notebook/console via ipylab. For example

from ipylab import JupyterFrontEnd
from ipylab import SessionContext
app = JupyterFrontEnd()
opts = SessionContext.currentSession()
# this will create a console with the current session.
# mimicking behavior of `notebook:create-console` command
app.commands.execute('console:create', opts)

Thanks @TK-21st!

That would indeed be very useful. I guess another way would be to get a hold on the current notebook (either the current notebook or by accessing the currentWidget from the notebook tracker), and get the session context with:

opts = notebook.sessionContext()

By the way if you feel like opening a PR (even as a draft), please don't hesitate!

By the way if you feel like opening a PR (even as a draft), please don't hesitate!

Just did! WIP on reporting the current kernel back.

Also I tried to define a bunch of HasTraits to map the interface from JLab's Typescript API but I clearly do not understand how traitlets are supposed to work 🙄 so that's WIP too..

The latest PR should have the feature necessary.

It was easy to show all sessions, since I can just expose app.serviceManager.sessions
It was a bit harder to make the currrentWidget work. I ended up exposing the private attribute app.shell._tracker which gives me access to the currently in focused widget and go from there.

Need to figure out linter still but it is functional

Thanks @TK-21st!

That would indeed be very useful. I guess another way would be to get a hold on the current notebook (either the current notebook or by accessing the currentWidget from the notebook tracker), and get the session context with:

opts = notebook.sessionContext()

I opted for using tracker since I wanted to potentially get the session of console widgets too. Turns out that's not working.. Comm open error.
Looks actually like a problem with using ipywidget in console.

opted for using tracker since I wanted to potentially get the session of console widgets too. Turns out that's not working.. Comm open error.
Looks actually like a problem with using ipywidget in console.

Right, the current JupyterLab widget manager does not handle consoles (yet).

Fixed by #46.