Skip to content

Commit

Permalink
AiidaCodeSetup: accept convert computer label to uuid (#408)
Browse files Browse the repository at this point in the history
When a computer label is received from a database it needs to be converted into
UUID to interact with `ComputerDropdownWidget`. Since awb 2.0 the `value` trait
of the latter can only be a UUID string.
  • Loading branch information
unkcpz authored Dec 8, 2022
1 parent bc9d065 commit 97f7b83
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
17 changes: 16 additions & 1 deletion aiidalab_widgets_base/computational_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import shortuuid
import traitlets
from aiida import common, orm, plugins
from aiida.common.exceptions import NotExistent
from aiida.orm.utils.builders.computer import ComputerBuilder
from aiida.transports.plugins.ssh import parse_sshconfig
from humanfriendly import InvalidSize, parse_size
Expand Down Expand Up @@ -163,7 +164,10 @@ def _get_codes(self):
return {
self._full_code_label(c[0]): c[0].uuid
for c in orm.QueryBuilder()
.append(orm.Code, filters={"attributes.input_plugin": self.input_plugin})
.append(
orm.Code,
filters={"attributes.input_plugin": self.input_plugin},
)
.all()
if c[0].computer.is_user_configured(user)
and (self.allow_hidden_codes or not c[0].is_hidden)
Expand Down Expand Up @@ -1131,6 +1135,17 @@ def _observe_code_setup(self, _=None):
getattr(self, key).label = value
except traitlets.TraitError:
self.message = f"Input plugin {value} is not installed."
elif key == "computer":
# check if the computer is set by load the label.
# if the computer not set put the value to None as placeholder for
# ComputerDropdownWidget it will refresh after the computer set up.
# if the computer is set pass the UUID to ComputerDropdownWdiget.
try:
computer = orm.load_computer(value)
except NotExistent:
getattr(self, key).value = None
else:
getattr(self, key).value = computer.uuid
else:
getattr(self, key).value = value

Expand Down
4 changes: 2 additions & 2 deletions notebooks/computational_resources.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -60,7 +60,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.4"
"version": "3.9.13"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 97f7b83

Please sign in to comment.