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 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 21 additions & 9 deletions aiidalab_widgets_base/computational_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,12 +483,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 @@ -615,10 +619,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
18 changes: 14 additions & 4 deletions aiidalab_widgets_base/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,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
2 changes: 1 addition & 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,7 @@ 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"))

@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
ipywidgets>=7,<9
pymysql~=0.9
nglview~=3.0
spglib>=1.14,<3
Expand All @@ -51,7 +50,7 @@ dev =
pytest-timeout~=2.3.0
selenium~=4.23.0
optimade =
ipyoptimade~=0.1
ipyoptimade==1.0.0
eln =
aiidalab-eln>=0.1.2,~=0.1
requests-cache~=1.0
Expand Down
Loading