-
Notifications
You must be signed in to change notification settings - Fork 507
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
Backward compat for ipywidgets 7 #1487
Closed
martinRenou
wants to merge
2
commits into
voila-dashboards:main
from
martinRenou:ipywidgets7_support
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/*************************************************************************** | ||
* Copyright (c) 2024, Voilà contributors * | ||
* Copyright (c) 2024, QuantStack * | ||
* * | ||
* Distributed under the terms of the BSD 3-Clause License. * | ||
* * | ||
* The full license is in the file LICENSE, distributed with this software. * | ||
****************************************************************************/ | ||
|
||
import * as base from '@jupyter-widgets/base'; | ||
import { | ||
JupyterFrontEnd, | ||
JupyterFrontEndPlugin | ||
} from '@jupyterlab/application'; | ||
|
||
const JUPYTER_WIDGETS_VERSION = '1.2.0'; | ||
const JUPYTER_CONTROLS_VERSION = '1.5.0'; | ||
|
||
/** | ||
* The base widgets. | ||
*/ | ||
export const baseWidgets7Plugin: JupyterFrontEndPlugin<void> = { | ||
id: `@jupyter-widgets/jupyterlab-manager:base-${JUPYTER_WIDGETS_VERSION}`, | ||
requires: [base.IJupyterWidgetRegistry], | ||
autoStart: true, | ||
activate: ( | ||
app: JupyterFrontEnd, | ||
registry: base.IJupyterWidgetRegistry | ||
): void => { | ||
registry.registerWidget({ | ||
name: '@jupyter-widgets/base', | ||
version: JUPYTER_WIDGETS_VERSION, | ||
exports: () => { | ||
require('./ipywidgets7shared'); | ||
return require('@jupyter-widgets/base7') as any; | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
/** | ||
* The control widgets. | ||
*/ | ||
export const controlWidgets7Plugin: JupyterFrontEndPlugin<void> = { | ||
id: `@jupyter-widgets/jupyterlab-manager:controls-${JUPYTER_CONTROLS_VERSION}`, | ||
requires: [base.IJupyterWidgetRegistry], | ||
autoStart: true, | ||
activate: ( | ||
app: JupyterFrontEnd, | ||
registry: base.IJupyterWidgetRegistry | ||
): void => { | ||
registry.registerWidget({ | ||
name: '@jupyter-widgets/controls', | ||
version: JUPYTER_CONTROLS_VERSION, | ||
exports: () => { | ||
require('./ipywidgets7shared'); | ||
const controlsWidgets = require('@jupyter-widgets/controls7') as any; | ||
require('@jupyter-widgets/controls7/css/widgets-base.css'); | ||
return controlsWidgets; | ||
} | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/*************************************************************************** | ||
* Copyright (c) 2024, Voilà contributors * | ||
* Copyright (c) 2024, QuantStack * | ||
* * | ||
* Distributed under the terms of the BSD 3-Clause License. * | ||
* * | ||
* The full license is in the file LICENSE, distributed with this software. * | ||
****************************************************************************/ | ||
|
||
export * as base from '@jupyter-widgets/base7'; | ||
export * as controls from '@jupyter-widgets/controls7'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/*************************************************************************** | ||
* Copyright (c) 2024, Voilà contributors * | ||
* Copyright (c) 2024, QuantStack * | ||
* * | ||
* Distributed under the terms of the BSD 3-Clause License. * | ||
* * | ||
* The full license is in the file LICENSE, distributed with this software. * | ||
****************************************************************************/ | ||
|
||
import * as base from '@jupyter-widgets/base'; | ||
import { | ||
JupyterFrontEnd, | ||
JupyterFrontEndPlugin | ||
} from '@jupyterlab/application'; | ||
|
||
const JUPYTER_WIDGETS_VERSION = '2.0.0'; | ||
const JUPYTER_CONTROLS_VERSION = '2.0.0'; | ||
|
||
/** | ||
* The base widgets. | ||
*/ | ||
export const baseWidgets8Plugin: JupyterFrontEndPlugin<void> = { | ||
id: `@jupyter-widgets/jupyterlab-manager:base-${JUPYTER_WIDGETS_VERSION}`, | ||
requires: [base.IJupyterWidgetRegistry], | ||
autoStart: true, | ||
activate: ( | ||
app: JupyterFrontEnd, | ||
registry: base.IJupyterWidgetRegistry | ||
): void => { | ||
registry.registerWidget({ | ||
name: '@jupyter-widgets/base', | ||
version: JUPYTER_WIDGETS_VERSION, | ||
exports: () => { | ||
require('./ipywidgets8shared'); | ||
return require('@jupyter-widgets/base') as any; | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
/** | ||
* The control widgets. | ||
*/ | ||
export const controlWidgets8Plugin: JupyterFrontEndPlugin<void> = { | ||
id: `@jupyter-widgets/jupyterlab-manager:controls-${JUPYTER_CONTROLS_VERSION}`, | ||
requires: [base.IJupyterWidgetRegistry], | ||
autoStart: true, | ||
activate: ( | ||
app: JupyterFrontEnd, | ||
registry: base.IJupyterWidgetRegistry | ||
): void => { | ||
registry.registerWidget({ | ||
name: '@jupyter-widgets/controls', | ||
version: JUPYTER_CONTROLS_VERSION, | ||
exports: () => { | ||
require('./ipywidgets8shared'); | ||
const controlsWidgets = require('@jupyter-widgets/controls') as any; | ||
require('@jupyter-widgets/controls/css/widgets-base.css'); | ||
return controlsWidgets; | ||
} | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/*************************************************************************** | ||
* Copyright (c) 2024, Voilà contributors * | ||
* Copyright (c) 2024, QuantStack * | ||
* * | ||
* Distributed under the terms of the BSD 3-Clause License. * | ||
* * | ||
* The full license is in the file LICENSE, distributed with this software. * | ||
****************************************************************************/ | ||
|
||
export * as base from '@jupyter-widgets/base'; | ||
export * as controls from '@jupyter-widgets/controls'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm having issues with the sharing logic which I'm not sure how to tackle.
We would need to have
@jupyter-widgets/base
be a shared package, but the version being loaded in the page would depend on the current ipywidgets version (model version requested by the kernel).In the current state of the PR,
@jupyter-widgets/base@6.0.6
is loaded.Would love to chat with you @jtpio or @trungleduc on this.
I will this PR as draft for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the use case we want to support? ipywidgets 7 and voila are installed in the same kernel env or ipywidgets 8 + voila in the base env and kernel env is using ipywidgets 7?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Voila in the base env and either ipywidgets 7 or 8 in the kernel env basically. Resulting in having Voila support both ipywidgets 7 or 8 if the kernel env is the voila base env.
For Voila 0.4.x that was easy using lazy loading of packages, and for some reason the package sharing logic did not come in my way when doing #1482. Maybe because the build setup did not use webpack federated packages?
Now in this PR, for some reason the webpack sharing package logic makes it that
@jupyter-widgets/base@6.0.6
is in the page and shared, which incompatible with@jupyter-widgets/controls
for ipywidgets 7 so you can't create aVBox
widget for example using ipywidgets 7 in the kernel. And we can't decide at build time which version of@jupyter-widgets/base
should be loaded and shared, I'd like to do that at runtime. Maybe overwriting__webpack_share_scopes__
at runtime in some way during the lazy load of the widget front-end?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested your PR with these configurations:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your testing! Yeah hopefully most cases would work, the one that does not work is:
Base = voila + ipywidgets7, Kernel = Base -> VBox does not work.
This is because of the issue I'm trying to explain up there in this thread with mismatching of versions between @jupyter-widgets/base and controls. We have base for 8 and controls for 7 in the page, thankfully most widgets do work in this case, but I'd really prefer to have base for 7 in the page in that case. And that's what I'm failing to figure out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I see. I think we should do the minimum for the ipywidgets backward compatible in Voila. The long-term solution is to adopt the voici/jupyterlab execution model. So that we only need to fix the backward issue once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned by @maartenbreddels in jupyter-widgets/ipywidgets#3932
I wonder if the two webpack bundles approach could suit us, one bundle with
@jupyter-widgets/base
for 7 being shared, another bundle with 8. And we load the bundle upon widget request depending on the widget version.So basically very similar to your suggestion @trungleduc
While making sure that the shared package is different for each bundle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I think it could work if we check for the widget version in the backend and write it to the page template
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah no I don't think checking in the back-end is a viable solution, ipywidgets may not be installed and if it is we don't know if it's the same version as in the kernel.
We'd still need to rely on the lazy loading logic from the widgets register, and lazy load one bundle or the other depending on what the kernel requests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
theoretically, we can peek at the kernel before generating the template, it can be the last resort if the lazy loading logic does not work.