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

Get rid of deprecation warnings in computational_resources.py #508

Merged
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
38 changes: 27 additions & 11 deletions aiidalab_widgets_base/computational_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,16 @@ def __init__(self, description="Select code:", path_to_root="../", **kwargs):
value=None,
style={"description_width": "initial"},
)
traitlets.link((self, "codes"), (self.code_select_dropdown, "options"))
traitlets.directional_link(
(self, "codes"),
(self.code_select_dropdown, "options"),
transform=lambda x: [(key, x[key]) for key in x],
)
traitlets.directional_link(
(self.code_select_dropdown, "options"),
(self, "codes"),
transform=lambda x: {c[0]: c[1] for c in x},
)
traitlets.link((self.code_select_dropdown, "value"), (self, "value"))

self.observe(
Expand Down Expand Up @@ -161,8 +170,8 @@ def _get_codes(self):

user = orm.User.collection.get_default()

return {
self._full_code_label(c[0]): c[0].uuid
return [
(self._full_code_label(c[0]), c[0].uuid)
for c in orm.QueryBuilder()
.append(
orm.Code,
Expand All @@ -172,7 +181,7 @@ def _get_codes(self):
if c[0].computer.is_user_configured(user)
and (self.allow_hidden_codes or not c[0].is_hidden)
and (self.allow_disabled_computers or c[0].computer.is_user_enabled(user))
}
]

@staticmethod
def _full_code_label(code):
Expand Down Expand Up @@ -335,7 +344,6 @@ def __init__(self, **kwargs):
self._inp_private_key = ipw.FileUpload(
accept="",
layout=LAYOUT,
style=STYLE,
description="Private key",
multiple=False,
)
Expand Down Expand Up @@ -1187,14 +1195,22 @@ def __init__(self, description="Select computer:", path_to_root="../", **kwargs)

self.output = ipw.HTML()
self._dropdown = ipw.Dropdown(
options={},
value=None,
description=description,
style=STYLE,
layout=LAYOUT,
disabled=True,
)
traitlets.link((self, "computers"), (self._dropdown, "options"))
traitlets.directional_link(
(self, "computers"),
(self._dropdown, "options"),
transform=lambda x: [(key, x[key]) for key in x],
)
traitlets.directional_link(
(self._dropdown, "options"),
(self, "computers"),
transform=lambda x: {c[0]: c[1] for c in x},
)
traitlets.link((self._dropdown, "value"), (self, "value"))

self.observe(self.refresh, names="allow_select_disabled")
Expand All @@ -1210,18 +1226,18 @@ def __init__(self, description="Select computer:", path_to_root="../", **kwargs)
self.refresh()
super().__init__(children=children, **kwargs)

def _get_computers(self):
def _get_computers(self) -> list:
"""Get the list of available computers."""

# Getting the current user.
user = orm.User.collection.get_default()

return {
c[0].label: c[0].uuid
return [
(c[0].label, c[0].uuid)
for c in orm.QueryBuilder().append(orm.Computer).all()
if c[0].is_user_configured(user)
and (self.allow_select_disabled or c[0].is_user_enabled(user))
}
]

def refresh(self, _=None):
"""Refresh the list of configured computers."""
Expand Down
4 changes: 2 additions & 2 deletions aiidalab_widgets_base/databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,15 @@ def __init__(self, **kwargs):
self.inp_computer = ipw.Dropdown(
options=[],
description="Computer:",
disable=False,
disabled=False,
)
self.inp_computer.observe(self._computer_changed, names=["value", "options"])

# Select code.
self.inp_code = ipw.Dropdown(
options=[],
description="Code:",
disable=False,
disabled=False,
)
self.inp_code.observe(self._code_changed, names=["value", "options"])

Expand Down
6 changes: 3 additions & 3 deletions tests/test_computational_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@


@pytest.mark.usefixtures("aiida_profile_clean")
def test_computaional_resources_widget(aiida_local_code_bash):
def test_computational_resources_widget(aiida_local_code_bash):
"""Test the ComputationalResourcesWidget."""
widget = computational_resources.ComputationalResourcesWidget(
default_calc_job_plugin="bash"
)

# Get the list of currently installed codes.
codes_dict = widget._get_codes()
assert "bash@localhost" in codes_dict
codes = widget._get_codes()
assert "bash@localhost" == codes[0][0]


@pytest.mark.usefixtures("aiida_profile_clean")
Expand Down
Loading