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

Add token ICellExecutor providing an entry to customize cell execution #15830

Merged
merged 13 commits into from
Mar 26, 2024

Conversation

fcollonval
Copy link
Member

References

Follow-up of the discussion jupyterlab/frontends-team-compass#229 (comment)
This will allow experimentation like #15448 to happen outside of core. It will also open the box for handling non-standard cell type execution for example (e.g. SQL cell).

Code changes

Provide the Private.runCell generic function as a plugin to allow customization.

User-facing changes

None

Backwards-incompatible changes

None

Copy link

Thanks for making a pull request to jupyterlab!
To try out this branch on binder, follow this link: Binder

@fcollonval
Copy link
Member Author

Failure are not related.

cc @echarles for awareness

*/
export const cellExecutor: JupyterFrontEndPlugin<ICellExecutor> = {
id: '@jupyterlab/notebook-extension:cell-executor',
description: 'Provides the notebook cell executor.',
Copy link
Member

Choose a reason for hiding this comment

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

What about console cells? These get executed as well and 90% of the code is shared with notebook. Since this is named ICellExecutor, should we make it handle either notebook or console (and then if in future another execution context comes along we can easily add it).

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought about it. But the two are quite different (presumably because they are separated). So should I try to reconciliate them or should the cell executor has two methods: runNotebookCell and runConsoleCell?

For reference, the console code is there:

private _execute(cell: CodeCell): Promise<void> {

Copy link
Member

Choose a reason for hiding this comment

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

So should I try to reconciliate them or should the cell executor has two methods: runNotebookCell and runConsoleCell?

I am not sure which would be better; I brought it up on the lab call yesterday but there were no strong opinions.

My thoughts:

  • The disadvantage of reconciliating them into one method is that implementers might need to do a few conditional logic blocks depending on the execution context
  • The disadvantage of two methods is that implementers would need to provide both, or we would need to have a default implementation as a fallback if we decided to make them optional (but then an interface with all methods optional risks that the implementer will fail to provide any if they make a typo and will be confused why nothing is working).

Thinking more about it, maybe there should be two separate plugins:

  • @jupyterlab/notebook-extension:cell-executor providing INotebookCellExecutor
  • @jupyterlab/console-extension:cell-executor providing IConsoleCellExecutor

Copy link
Member

Choose a reason for hiding this comment

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

Separate plugins sounds better in the sense that additional execution context means just a new plugin, and that there is no need to have any fallbacks/optional methods, and no conditional logic.

The downside is that adding new execution context does require implementers to add a new plugin, but realistically this is something which does not happen frequently so I think this is a good trade-off.

Copy link
Member Author

Choose a reason for hiding this comment

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

Having two plugins seems a good path. Thanks for bringing this PR for discussion at the call.

Copy link
Member

Choose a reason for hiding this comment

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

So I think the minimum required change for this PR would be renaming ICellExecutor to INotebookCellExecutor.

@fcollonval
Copy link
Member Author

Ok I pushed this one forward; 🤞 for the CI.

For the reviewer I have a final wording question, should it be I...CellExector.runCell (current version) or I...CellExecutor.run?

@krassowski
Copy link
Member

should it be I...CellExector.runCell (current version) or I...CellExecutor.run?

I like how runCell how gives us freedom to expand this interface to include something like runAllCells in the future if needed (not saying that this is a good idea, just saying that having more specific names might be more future-proof).

@krassowski
Copy link
Member

Kicking CI after bot updates

@krassowski krassowski closed this Mar 23, 2024
@krassowski krassowski reopened this Mar 23, 2024
@krassowski
Copy link
Member

The test failure in js-console group appears relevant:

  ● console/widget › CodeConsole › #executed › should emit a date upon execution

    expect(received).toBeInstanceOf(expected)

    Expected constructor: Date

    Received value has no prototype
    Received value: null

      104 |         await (widget.sessionContext as SessionContext).initialize();
      105 |         await widget.execute(force);
    > 106 |         expect(called).toBeInstanceOf(Date);
          |                        ^
      107 |       });
      108 |     });
      109 |

      at Object.<anonymous> (test/widget.spec.ts:106:24)

@fcollonval
Copy link
Member Author

Thanks @krassowski

I fixed the code and rename the console/src/executor.ts to console/src/cellexecutor.ts to align naming.

Copy link
Member

@krassowski krassowski left a comment

Choose a reason for hiding this comment

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

Just one suggestion on renaming IExecutionOptions or nesting them in namespaces.

packages/console/src/tokens.ts Outdated Show resolved Hide resolved
packages/notebook/src/tokens.ts Outdated Show resolved Hide resolved
@fcollonval
Copy link
Member Author

Thanks @krassowski I went for the namespacing as it is a common pattern in core and will be a good fit in case new API are added to the executors.

I used IRunCellOptions instead of IOptions as the later is usually used for constructor. Moreover in case of a API extension the generic IOptions for runCell may bring confusion.

Copy link
Member

@krassowski krassowski left a comment

Choose a reason for hiding this comment

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

Thank you @fcollonval.

I would personally prefix the namespaces with I (which is already common in the codebase) to take advantage of declaration merging, but I know it was called confusing by some new contributors so I am equally happy to go with the current version.

@fcollonval
Copy link
Member Author

fcollonval commented Mar 26, 2024

I would personally prefix the namespaces with I (which is already common in the codebase) to take advantage of declaration merging, but I know it was called confusing by some new contributors so I am equally happy to go with the current version.

done in 71cc3c9

@krassowski
Copy link
Member

The visual test failure is relevant. Maybe I should mock the descriptions, but for now updating it.

bot please update documentation snapshots

Copy link
Contributor

Documentation snapshots updated.

@fcollonval
Copy link
Member Author

Kicking the CI

Copy link
Member

Choose a reason for hiding this comment

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

Flaky snapshot update (a kernel from another test was captured). I feel like we need to mock the kernels out for some tests.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the help

@krassowski krassowski merged commit 424806b into jupyterlab:main Mar 26, 2024
81 checks passed
@fcollonval fcollonval deleted the ft/add-cell-executor branch March 27, 2024 08:36
krassowski added a commit to krassowski/jupyterlab that referenced this pull request Mar 28, 2024
…ion (jupyterlab#15830)

* Add token `ICellExecutor` providing an entry to customize cell execution

* Apply review comments to the notebook package

* Add console cell executor

* Some fixes

* Automatic application of license header

* Fix unit test

* Align naming

* Namespace the interfaces and rename them

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Prefix namespace with `I`

* Update Playwright Snapshots

* Revert flaky snapshot update

---------

Co-authored-by: Frédéric Collonval <fcollonval@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Michał Krassowski <5832902+krassowski@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants