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

Update to ipywidgets 8 #282

Merged
merged 44 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
e2e0f65
First attempt
ibdafna Dec 7, 2021
c900d81
Rename interface in plugin.js
ibdafna Dec 7, 2021
8a66902
Remove kwargs from super init (eliminates a warning)
ibdafna Jan 25, 2022
2a08995
Add ipywidgets 7 compatibility
ibdafna Apr 20, 2022
6f66955
Remove base-manager from package file
ibdafna Apr 20, 2022
a4379eb
Clean print statements
ibdafna Apr 20, 2022
d429770
Update version of jest/jest types, update jest config
ibdafna Apr 20, 2022
16ce250
index_name as optional positional argument
ibdafna Apr 20, 2022
778ce34
Separate test suites for ipywidgets 7/8
ibdafna Aug 24, 2022
f831631
Fix pandas version in test cases
ibdafna Aug 25, 2022
8a7c1b5
Remove EOL nodejs version from testing
ibdafna Aug 25, 2022
676a21c
Add old test environment file back
ibdafna Aug 25, 2022
2fb2008
Update Playwright Snapshots
github-actions[bot] Aug 25, 2022
4b1be56
PhosphorPanelWidget shim
ibdafna Sep 11, 2022
916d0dc
Add pWidget getter
ibdafna Sep 28, 2022
7b236a5
Update Playwright Snapshots
github-actions[bot] Sep 28, 2022
9be05ac
Update lockfile
ibdafna Sep 29, 2022
31260a1
Update test to reflect latest pandas version, update lockfile
ibdafna Jan 25, 2022
1367ed0
Remove kwargs from super init (eliminates a warning)
ibdafna Jan 25, 2022
29fb02b
Clean print statements
ibdafna Apr 20, 2022
89fbf84
index_name as optional positional argument
ibdafna Apr 20, 2022
edd67d3
Update widgets/base package, remove upper bound pin on ipywidgets ver…
ibdafna Apr 29, 2022
6b3e619
Bump shell-quote from 1.7.2 to 1.7.3
dependabot[bot] Jun 24, 2022
ce3f021
Update test to reflect latest pandas version, update lockfile
ibdafna Jan 25, 2022
57e1268
Update widgets/base package, remove upper bound pin on ipywidgets ver…
ibdafna Apr 29, 2022
0a641a5
Fix Jest issues 🤎
ibdafna Aug 24, 2022
ac1c06e
Add widget base 6 as dep
ibdafna Aug 24, 2022
1ce6cca
Update package lockfile 🔒
ibdafna Aug 24, 2022
584c84c
Separate test suites for ipywidgets 7/8
ibdafna Aug 24, 2022
3a2f09a
Update lockfile 🔒
ibdafna Aug 24, 2022
0c26a2d
Fix filenames, drop nodejs version to 14
ibdafna Aug 25, 2022
7622cc6
Update ipywidgets version to 8
ibdafna Aug 25, 2022
801f18c
Update ipywidgets version to 8
ibdafna Aug 25, 2022
54518b0
Appease linter
ibdafna Aug 25, 2022
9e07e26
Fix pandas version in expected output object
ibdafna Aug 25, 2022
85487aa
Update Galata test env file name
ibdafna Aug 25, 2022
74b5005
Add old test environment file back
ibdafna Aug 25, 2022
77bd90c
Update Playwright Snapshots
github-actions[bot] Aug 25, 2022
fca4079
Update Playwright Snapshots
github-actions[bot] Sep 28, 2022
b3e11da
Split ui-testing for ipw7/8
ibdafna Sep 29, 2022
e90475e
Update venv names for split testing
ibdafna Sep 29, 2022
1e5b36c
Update Playwright Snapshots
github-actions[bot] Sep 29, 2022
ba8251c
Update lockfile
ibdafna Sep 29, 2022
3ee8a99
Update lockfile 🔑
ibdafna Sep 29, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 68 additions & 19 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
push:
pull_request:
schedule:
- cron: "0 8 * * *"
- cron: '0 8 * * *'

defaults:
run:
Expand All @@ -20,7 +20,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: '3.10'
- uses: pre-commit/action@v3.0.0

test:
Expand All @@ -30,18 +30,18 @@ jobs:
fail-fast: false
matrix:
py:
- "3.10"
- "3.9"
- "3.8"
- "3.7"
- "3.6"
- '3.10'
- '3.9'
- '3.8'
- '3.7'
- '3.6'
- pypy3.7
steps:
- uses: actions/checkout@v3
- name: setup python for tox
uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: '3.10'
- name: install tox
run: python -m pip install tox
- name: setup python for test ${{ matrix.py }}
Expand Down Expand Up @@ -77,7 +77,7 @@ jobs:
- name: setup Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: '3.10'
- name: install tox
run: python -m pip install tox
- name: run check for ${{ matrix.tox_env }}
Expand All @@ -91,7 +91,7 @@ jobs:
- name: setup python to build package
uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: '3.10'
- name: install build
run: python -m pip install build
- uses: actions/checkout@v3
Expand All @@ -104,7 +104,7 @@ jobs:
user: __token__
password: ${{ secrets.pypi_password }}

visual-regression-tests:
visual-regression-tests-ipw7:
runs-on: ubuntu-latest

steps:
Expand All @@ -114,10 +114,10 @@ jobs:
- name: Setup conda
uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: ipydatagrid-test
environment-file: test-environment.yaml
activate-environment: ipydatagrid-test-ipw7
environment-file: test-environment-ipyw7.yaml
python-version: 3.9
mamba-version: "*"
mamba-version: '*'
auto-activate-base: false
channels: conda-forge

Expand All @@ -128,11 +128,11 @@ jobs:
run: |
yarn install
yarn playwright install chromium
working-directory: ui-tests
working-directory: ui-tests-ipw7

- name: Launch JupyterLab
run: yarn run start:detached
working-directory: ui-tests
working-directory: ui-tests-ipw7

- name: Wait for JupyterLab
uses: ifaxity/wait-on-action@v1
Expand All @@ -142,13 +142,62 @@ jobs:

- name: Run UI Tests
run: yarn run test
working-directory: ui-tests
working-directory: ui-tests-ipw7

- name: Upload UI Test artifacts
if: always()
uses: actions/upload-artifact@v3
with:
name: ui-test-output
path: |
ui-tests/playwright-report
ui-tests/test-results
ui-tests-ipw7/playwright-report
ui-tests-ipw7/test-results

visual-regression-tests-ipw8:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup conda
uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: ipydatagrid-test-ipw8
environment-file: test-environment-ipyw8.yaml
python-version: 3.9
mamba-version: '*'
auto-activate-base: false
channels: conda-forge

- name: Install the package
run: pip install -vv .

- name: Install Galata
run: |
yarn install
yarn playwright install chromium
working-directory: ui-tests-ipw8

- name: Launch JupyterLab
run: yarn run start:detached
working-directory: ui-tests-ipw8

- name: Wait for JupyterLab
uses: ifaxity/wait-on-action@v1
with:
resource: http-get://localhost:8888/api
timeout: 20000

- name: Run UI Tests
run: yarn run test
working-directory: ui-tests-ipw8

- name: Upload UI Test artifacts
if: always()
uses: actions/upload-artifact@v3
with:
name: ui-test-output
path: |
ui-tests-ipw8/playwright-report
ui-tests-ipw8/test-results
2 changes: 1 addition & 1 deletion .github/workflows/jest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x, 12.x, 14.x]
node-version: [14.x]

steps:
- uses: actions/checkout@v3
Expand Down
18 changes: 9 additions & 9 deletions binder/environment.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: ipydatagrid
channels:
- conda-forge
- conda-forge
dependencies:
- ipywidgets=7.6
- jupyterlab=3
- numpy
- nodejs
- pandas
- pip
- pip:
- ..
- ipywidgets=8.0
- jupyterlab=3
- numpy
- nodejs
- pandas
- pip
- pip:
- ..
8 changes: 2 additions & 6 deletions ipydatagrid/datagrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,14 +359,10 @@ class DataGrid(DOMWidget):
{"area": "all", "padding": 30, "numCols": None}, allow_none=False
).tag(sync=True)

def __init__(self, dataframe, **kwargs):
def __init__(self, dataframe, index_name=None, **kwargs):
# Setting default index name if not explicitly
# set by the user.
if "index_name" in kwargs:
self._index_name = kwargs["index_name"]
else:
self._index_name = None

self._index_name = index_name
self.data = dataframe
super().__init__(**kwargs)
self._cell_click_handlers = CallbackDispatcher()
Expand Down
3 changes: 2 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ module.exports = {
'^.+\\.js$': 'babel-jest',
},
transformIgnorePatterns: ['node_modules/?!(@jupyter-widgets)'],
testPathIgnorePatterns: ['ui-tests/'],
testPathIgnorePatterns: ['ui-tests-ipw7/', 'ui-tests-ipw8/'],
setupFiles: ['./tests/js/setupFile.js'],
testEnvironment: 'jsdom',
moduleNameMapper: {
'\\.(css|less)$': '<rootDir>/__mocks__/styleMock.js',
},
Expand Down
67 changes: 48 additions & 19 deletions js/datagrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@ import { CellRenderer } from '@lumino/datagrid';

import { JSONExt } from '@lumino/coreutils';

import { MessageLoop, Message } from '@lumino/messaging';
import { Message, MessageLoop } from '@lumino/messaging';

import { Widget } from '@lumino/widgets';

import {
DOMWidgetModel,
DOMWidgetView,
JupyterPhosphorPanelWidget,
ICallbacks,
ISerializers,
JupyterLuminoPanelWidget,
//@ts-ignore needed for ipywidgetx 7.x compatibility
JupyterPhosphorPanelWidget,
resolvePromisesDict,
unpack_models,
WidgetModel,
ICallbacks,
WidgetModel
} from '@jupyter-widgets/base';

import { ViewBasedJSONModel } from './core/viewbasedjsonmodel';
Expand Down Expand Up @@ -340,36 +342,58 @@ function unpack_data(

export class DataGridView extends DOMWidgetView {
_createElement(tagName: string) {
this.pWidget = new JupyterPhosphorPanelWidget({ view: this });
const panelWidget = Private.getWidgetPanel();
this.luminoWidget = new panelWidget({ view: this });
this._initializeTheme();
return this.pWidget.node;
return this.luminoWidget.node;
}

// Added for ipywidgets 7.x compatibility
get pWidget(): any {
return this.luminoWidget;
}

_setElement(el: HTMLElement) {
if (this.el || el !== this.pWidget.node) {
if (this.el || el !== this.luminoWidget.node) {
throw new Error('Cannot reset the DOM element.');
}

this.el = this.pWidget.node;
this.el = this.luminoWidget.node;
}

manageResizeEvent = () => {
MessageLoop.postMessage(this.pWidget, Widget.ResizeMessage.UnknownSize);
MessageLoop.postMessage(
this.luminoWidget,
Widget.ResizeMessage.UnknownSize,
);
};

processPhosphorMessage(msg: Message): void {
super.processPhosphorMessage(msg);
// ipywidgets 7 compatibility
_processLuminoMessage(
msg: Message,
_super: DOMWidgetView['processLuminoMessage'],
): void {
_super.call(this, msg);

switch (msg.type) {
case 'after-show':
if (this.pWidget.isVisible) {
if (this.luminoWidget.isVisible) {
this.manageResizeEvent();
}
break;
}
}

render() {
processLuminoMessage(msg: Message): void {
this._processLuminoMessage(msg, super.processLuminoMessage);
}

processPhosphorMessage(msg: Message): void {
//@ts-ignore needed for ipywidgets 7.x compatibility
this._processLuminoMessage(msg, super.processPhosphorMessage);
}

render(): Promise<void> {
this.el.classList.add('datagrid-container');
window.addEventListener('resize', this.manageResizeEvent);
this.once('remove', () => {
Expand Down Expand Up @@ -496,7 +520,7 @@ export class DataGridView extends DOMWidgetView {
return this.updateRenderers().then(() => {
this.updateGridStyle();
this.updateGridRenderers();
this.pWidget.addWidget(this.grid);
this.luminoWidget.addWidget(this.grid);
});
}

Expand Down Expand Up @@ -698,7 +722,7 @@ export class DataGridView extends DOMWidgetView {
default_renderer: CellRendererView;
header_renderer: CellRendererView;
grid: FeatherGrid;
pWidget: JupyterPhosphorPanelWidget;
luminoWidget: JupyterLuminoPanelWidget;
model: DataGridModel;
backboneModel: DataGridModel;

Expand All @@ -707,16 +731,15 @@ export class DataGridView extends DOMWidgetView {
}

export {
TextRendererModel,
TextRendererView,
BarRendererModel,
BarRendererView,
HyperlinkRendererModel,
HyperlinkRendererView,
HyperlinkRendererView, TextRendererModel,
TextRendererView
} from './cellrenderer';

export { VegaExprModel, VegaExprView } from './vegaexpr';


export namespace DataGridModel {
/**
* An options object for initializing the data model.
Expand All @@ -742,6 +765,12 @@ export namespace DataGridModel {
* The namespace for the module implementation details.
*/
namespace Private {
export function getWidgetPanel(): any {
//@ts-ignore needed for ipywidget 7.x compatibility
return JupyterLuminoPanelWidget ?? JupyterPhosphorPanelWidget;
}


/**
* Creates a valid JSON Table Schema from the schema provided by pandas.
*
Expand Down
2 changes: 1 addition & 1 deletion js/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function activateWidgetExtension(
): void {
// Exporting a patched DataGridView widget which handles dynamic theme changes
class DataGridView extends widgetExports.DataGridView {
initialize(parameters: WidgetView.InitializeParameters) {
initialize(parameters: WidgetView.IInitializeParameters) {
if (themeManager.theme != null) {
this.isLightTheme = themeManager.isLight(themeManager.theme);
}
Expand Down
Loading