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

Support ipywidgets 8.x #644

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
Draft
30 changes: 21 additions & 9 deletions aiidalab_widgets_base/computational_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,12 +497,16 @@ def _on_setup_ssh_button_pressed(self, _=None):
self.message = wrap_message(message, MessageLevel.ERROR)
return

filename = Path(private_key_fname).name

# if the private key filename is exist, generate random string and append to filename subfix
# if the private key filename exists, generate random string and append to filename subfix
# then override current name.
if filename in [str(p.name) for p in Path(self._ssh_folder).iterdir()]:
private_key_fpath = self._ssh_folder / f"{filename}-{shortuuid.uuid()}"
if private_key_fname in [
str(p.name) for p in Path(self._ssh_folder).iterdir()
]:
private_key_fpath = (
self._ssh_folder / f"{private_key_fname}-{shortuuid.uuid()}"
)
else:
private_key_fpath = self._ssh_folder / private_key_fname

self._add_private_key(private_key_fpath, private_key_content)

Expand Down Expand Up @@ -629,10 +633,18 @@ def _on_verification_mode_change(self, change):
def _private_key(self) -> tuple[str | None, bytes | None]:
"""Unwrap private key file and setting filename and file content."""
if self._inp_private_key.value:
(fname, _value), *_ = self._inp_private_key.value.items()
content = copy.copy(_value["content"])
self._inp_private_key.value.clear()
self._inp_private_key._counter = 0 # pylint: disable=protected-access
try:
(fname, value), *_ = (
(fname, item["content"])
for fname, item in self._inp_private_key.value.items()
) # ipywidgets 7.x
value = value["content"]
except AttributeError:
(fname, value), *_ = (
(f["name"], f.content.tobytes())
for f in self._inp_private_key.value
) # ipywidgets 8.x
content = copy.copy(value)
return fname, content
return None, None

Expand Down
4 changes: 0 additions & 4 deletions aiidalab_widgets_base/databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,6 @@ def __init__(
skip_providers=kwargs.pop(
"skip_providers", default_parameters.SKIP_DATABASE
),
provider_database_groupings=kwargs.pop(
"provider_database_groupings",
default_parameters.PROVIDER_DATABASE_GROUPINGS,
),
)
filters = query_filter.OptimadeQueryFilterWidget(
embedded=embedded,
Expand Down
18 changes: 14 additions & 4 deletions aiidalab_widgets_base/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,20 @@ def _validate_and_fix_ase_cell(self, ase_structure, vacuum_ang=10.0):

def _on_file_upload(self, change=None):
"""When file upload button is pressed."""
for fname, item in change["new"].items():
self.structure = self._read_structure(fname, item["content"])
self.file_upload.value.clear()
break

def get_unified_representation(value):
"""This function ensures backwards compatibility w.r.t. ipywidgets 7.x"""
try:
return [
(fname, item["content"]) for fname, item in value.items()
] # ipywidgets 7.x
except AttributeError:
return [
(f["name"], f.content.tobytes()) for f in value
] # ipywidgets 8.x

fname, item = get_unified_representation(change["new"])[0]
self.structure = self._read_structure(fname, item)

def _read_structure(self, fname, content):
suffix = "".join(pathlib.Path(fname).suffixes)
Expand Down
3 changes: 2 additions & 1 deletion aiidalab_widgets_base/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ def __init__(self, steps, show_header=True, **kwargs):
# Initialize the accordion with the widgets ...
self.accordion = ipw.Accordion(children=widgets)
self._update_titles()
ipw.link((self.accordion, "selected_index"), (self, "selected_index"))

# Watch for changes to each step's state
for widget in widgets:
Expand Down Expand Up @@ -148,6 +147,8 @@ def __init__(self, steps, show_header=True, **kwargs):
self.show_header = show_header

super().__init__(children=[self.header, self.accordion], **kwargs)
ipw.link((self.accordion, "selected_index"), (self, "selected_index"))
self.selected_index = 0

@property
def show_header(self):
Expand Down
5 changes: 2 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ install_requires =
humanfriendly~=10.0
ipytree~=0.2
traitlets~=5.4
ipywidgets~=7.7
widgetsnbextension<3.6.3
Copy link
Contributor

Choose a reason for hiding this comment

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

Great to remove this. 🚀 Have you tested that the original reason for this widgetsnbextension pin no longer applies? (I think it was because of the NodeTree widget was broken?)

EDIT: It looks like we still need the widgetsnbextension based on our experience of omitting it in aiidalab-home. See this issue aiidalab/aiidalab-docker-stack#512 Definitely will need testing.

ipywidgets>=7.7,<9
pymysql~=0.9
nglview~=3.0
spglib>=1.14,<3
Expand All @@ -52,7 +51,7 @@ dev =
pytest-timeout~=2.3.0
selenium~=4.23.0
optimade =
ipyoptimade~=0.1
ipyoptimade>=1.2.1,<2
eln =
aiidalab-eln>=0.1.2,~=0.1
requests-cache~=1.0
Expand Down
12 changes: 7 additions & 5 deletions tests/test_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ def test_open_aiida_node_in_app_widget(multiply_add_completed_workchain):
open_node_in_app.node = process

assert len(open_node_in_app.tab.children) > 0
assert open_node_in_app.tab._titles == {
"0": "Geometry Optimization",
"1": "Geometry analysis",
"2": "Isotherm",
}
expected_tab_titles = [
"Geometry Optimization",
"Geometry analysis",
"Isotherm",
]
for i in range(len(open_node_in_app.tab.children)):
assert open_node_in_app.tab.get_title(i) == expected_tab_titles[i]
Loading