Skip to content
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

Exposing current sessionContext to ipylab #43

Closed
TK-21st opened this issue May 27, 2020 · 7 comments
Closed

Exposing current sessionContext to ipylab #43

TK-21st opened this issue May 27, 2020 · 7 comments

Comments

@TK-21st
Copy link
Contributor

TK-21st commented May 27, 2020

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)
@jtpio
Copy link
Owner

jtpio commented May 27, 2020

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()

@jtpio
Copy link
Owner

jtpio commented May 27, 2020

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

@TK-21st
Copy link
Contributor Author

TK-21st commented May 27, 2020

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..

@TK-21st
Copy link
Contributor Author

TK-21st commented May 27, 2020

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

@TK-21st
Copy link
Contributor Author

TK-21st commented May 27, 2020

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.

@jtpio
Copy link
Owner

jtpio commented May 28, 2020

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).

@jtpio
Copy link
Owner

jtpio commented Jun 2, 2020

Fixed by #46.

@jtpio jtpio closed this as completed Jun 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants