From 7392d02eb449dbea5b6f116ff0892fbe9eb6e7a4 Mon Sep 17 00:00:00 2001 From: Daniel Hollas Date: Wed, 24 Jan 2024 09:08:15 +0000 Subject: [PATCH] dataclass? --- aiidalab_launch/__main__.py | 6 +++--- aiidalab_launch/profile.py | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/aiidalab_launch/__main__.py b/aiidalab_launch/__main__.py index 633a704..d2a54a2 100644 --- a/aiidalab_launch/__main__.py +++ b/aiidalab_launch/__main__.py @@ -54,7 +54,7 @@ Home mounted: {home_mount} -> /home/{system_user}""" -MSG_EXTRA_MOUNT = "Extra {mount_type} mount: {source} -> {target} {rw_mode}" +MSG_EXTRA_MOUNT = "Extra {mount_type} mount: {source} -> {target} {mode}" LOGGING_LEVELS = { @@ -473,14 +473,14 @@ async def _async_start( ) for extra_mount in profile.extra_mounts: - source, target, rw_mode, mount_type = profile.parse_extra_mount( + source, target, mode, mount_type = profile.parse_extra_mount( extra_mount ) click.secho( MSG_EXTRA_MOUNT.format( source=source, target=target, - rw_mode=rw_mode, + mode=mode, mount_type=mount_type, ).lstrip(), fg="green", diff --git a/aiidalab_launch/profile.py b/aiidalab_launch/profile.py index 2e6aae1..0fad645 100644 --- a/aiidalab_launch/profile.py +++ b/aiidalab_launch/profile.py @@ -61,6 +61,15 @@ def _get_aiidalab_default_apps(container: Container) -> list: except KeyError: return [] +@dataclass +class ExtraMount: + source: str + target: str + mode: str # TOOD: Make this a Literal + type: str + + @classmethod + def from_string(cls, string): @dataclass class Profile: @@ -90,10 +99,10 @@ def __post_init__(self): # Normalize extra mount mode to be "rw" by default # so that we match Docker default but are explicit. for extra_mount in self.extra_mounts.copy(): - _, _, rw_mode, _ = self.parse_extra_mount(extra_mount) + _, _, mode, _ = self.parse_extra_mount(extra_mount) if len(extra_mount.split(":")) == 2: self.extra_mounts.remove(extra_mount) - self.extra_mounts.add(f"{extra_mount}:{rw_mode}") + self.extra_mounts.add(f"{extra_mount}:{mode}") if ( self.image.split(":")[0] == "aiidalab/full-stack" @@ -126,9 +135,8 @@ def parse_extra_mount( # By default, extra mounts are writeable mode = fields[2] if len(fields) == 3 else "rw" - # TODO: Convert to enum if mode not in ("ro", "rw"): - raise ValueError(f"Invalid extra mount mode '{mode}'") + raise ValueError(f"Invalid extra mount mode '{mode}' in '{extra_mount}''") return source_path, target_path, mode, mount_type