Skip to content

Commit

Permalink
Adding support for orm.Containerized codes.
Browse files Browse the repository at this point in the history
This is obtained using the AiidaCodeSetup().code_setup attribute.
I am not sure is the right way, as we should also provide the possibility
to change the `image_name` and the `engine_command` via the GUI.
  • Loading branch information
mikibonacci committed Jul 4, 2024
1 parent d8b7e71 commit 9271ecf
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions aiidalab_widgets_base/computational_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -1196,16 +1196,26 @@ def on_setup_code(self, _=None):
"append_text",
]

containerized_codes_additional_items = [
"image_name",
"engine_command",
]

kwargs = {key: getattr(self, key).value for key in items_to_configure}

# Check for additional keys needed for orm.ContainerizedCode
for container_key in containerized_codes_additional_items:
if container_key in self.code_setup.keys():
kwargs[container_key] = self.code_setup[container_key]

# set computer from its widget value the UUID of the computer.
computer = orm.load_computer(self.computer.value)

# Checking if the code with this name already exists
qb = orm.QueryBuilder()
qb.append(orm.Computer, filters={"uuid": computer.uuid}, tag="computer")
qb.append(
orm.InstalledCode,
(orm.InstalledCode, orm.ContainerizedCode),
with_computer="computer",
filters={"label": kwargs["label"]},
)
Expand All @@ -1223,7 +1233,10 @@ def on_setup_code(self, _=None):
return False

try:
code = orm.InstalledCode(computer=computer, **kwargs)
if "image_name" in kwargs.keys():
code = orm.ContainerizedCode(computer=computer, **kwargs)
else:
code = orm.InstalledCode(computer=computer, **kwargs)
except (common.exceptions.InputValidationError, KeyError) as exception:
self.message = wrap_message(
f"Invalid input for code creation: <code>{exception}</code>",
Expand Down

0 comments on commit 9271ecf

Please sign in to comment.