Skip to content

Commit

Permalink
dataclass?
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhollas committed Jan 24, 2024
1 parent fceb1c4 commit 7392d02
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
6 changes: 3 additions & 3 deletions aiidalab_launch/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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",
Expand Down
16 changes: 12 additions & 4 deletions aiidalab_launch/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 7392d02

Please sign in to comment.