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 session information to kernel #44

Closed
wants to merge 13 commits into from
Closed

Conversation

TK-21st
Copy link
Contributor

@TK-21st TK-21st commented May 27, 2020

addresses #43

  • exposing the global sessionManager instance to user (app.serviceManager.sessions)
  • function for giving current session to the user
  • Lint
    • ESlint
    • Pylint

@jtpio
Copy link
Owner

jtpio commented May 28, 2020

Thanks @TK-21st for this!

@jtpio
Copy link
Owner

jtpio commented May 28, 2020

It should be possible to fix the failing Python lint job by running black locally with:

black .

Although the pre-commit hook should run it by default on commit.

src/plugin.ts Outdated
@@ -36,6 +38,9 @@ const extension: JupyterFrontEndPlugin<void> = {
widgetExports.ShellModel.shell = shell;
widgetExports.CommandRegistryModel.commands = app.commands;
widgetExports.CommandPaletteModel.palette = palette;
widgetExports.SessionManagerModel.sessions = app.serviceManager.sessions;
const focusTracker: FocusTracker<any> = (app.shell as any)._tracker;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering whether this should be the lab shell focus tracker, or the INotebookTracker and IConsoleTracker?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to clean that up I feel.

But I was also considering the super edge-case where the user wants to use, say, CodeCell in a custom extension not tracked by INotebookTracker or IConsoleTracker, and hope to inject some code there with ipylab, then this won't work.

But then again, a SUPER edge case.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but it could indeed be useful! Maybe we could track that in a separate issue?

But I was also considering the super edge-case where the user wants to use, say, CodeCell in a custom extension not tracked by INotebookTracker or IConsoleTracker, and hope to inject some code there with ipylab, then this won't work.

The custom extension could provide its own track (ICustomTracker), and then ipylab could require this token as optional in the activate function. Although that would mean making a change to ipylab everytime we need to support a new extension. So yes a more general focus tracker could probably scale better.

Copy link
Contributor Author

@TK-21st TK-21st May 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but it could indeed be useful! Maybe we could track that in a separate issue?

Sure!

So yes a more general focus tracker could probably scale better.

Agreed! So would you say we go with INotebookTracker and IConsoleTracker for now or keep using the generic FocusTracker as it is now?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed! So would you say we go with INotebookTracker and IConsoleTracker for now or keep using the generic FocusTracker as it is now?

I'll give it a try locally to see what it looks like with the FocusTracker.

At first it felt more natural to go with INotebookTracker and IConsoleTracker as those are the "public" tracker exposed from the notebook and console extensions. Also we can add them as optional in the activate function. Which means they are available only if the environment provides them (would be interesting to try in a custom lab build some day! #33)

But if the focus tracker might just keep things simpler actually! (checking for widget.sessionContext.session? directly).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also ILabShell has a currentWidget and currentChanged (and is already exposed as Shell in ipylab).

Maybe this could be a substitute to the focus tracker?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also ILabShell has a currentWidget and currentChanged (and is already exposed as Shell in ipylab).

Maybe this could be a substitute to the focus tracker?

Ooo, I did not know that.. that'd certainly be better than exposing a private attribute..
Let me change that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to using shell.

@TK-21st
Copy link
Contributor Author

TK-21st commented May 28, 2020

Turns out it needed to format '''docstring with single quotes''' to """docstring with double quotes""". Black really is

the uncompromising Python code formatter

😮

src/widgets/sessions.ts Outdated Show resolved Hide resolved
@TK-21st
Copy link
Contributor Author

TK-21st commented May 29, 2020

Sorry was trying to play with some code in a separate repo and accidentally pushed to the wrong remote.

@TK-21st
Copy link
Contributor Author

TK-21st commented May 29, 2020

reverted the dumb mistake in #45.

@TK-21st TK-21st closed this May 29, 2020
jtpio added a commit that referenced this pull request Jun 2, 2020
Exposing `session` information to kernel (fix a commit error in #44)
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

Successfully merging this pull request may close these issues.

2 participants