From 4c4c3ff15a82eb6278efbc2dfd919c4e2efd109c Mon Sep 17 00:00:00 2001 From: Felix Stupp Date: Fri, 5 Aug 2022 11:55:45 +0000 Subject: [PATCH] defs/compose: Add typings for service volumes --- podman_compose_tools/defs/compose/__init__.py | 1 + podman_compose_tools/defs/compose/service.py | 83 +++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/podman_compose_tools/defs/compose/__init__.py b/podman_compose_tools/defs/compose/__init__.py index 2f5d2d4..a2e1f8a 100644 --- a/podman_compose_tools/defs/compose/__init__.py +++ b/podman_compose_tools/defs/compose/__init__.py @@ -6,6 +6,7 @@ from .service import ( ServiceName, ContainerName, ServiceDef as ComposeServiceDef, + VolumeDef as ComposeServiceVolumeDef, ) from .volume import ( VolumeName, diff --git a/podman_compose_tools/defs/compose/service.py b/podman_compose_tools/defs/compose/service.py index 1617776..f7a65da 100644 --- a/podman_compose_tools/defs/compose/service.py +++ b/podman_compose_tools/defs/compose/service.py @@ -10,3 +10,86 @@ ContainerName = NewType("ContainerName", str) class ServiceDef(TypedDict, total=False): container_name: ContainerName depends_on: Sequence[ServiceName] + volumes: Sequence[VolumeDef] + + +# === Service Volumes + + +_VolumeShort = NewType("_VolumeShort", str) +"format: [SOURCE:]TARGET[:MODE] where MODE is either rw or ro" + + +class _VolumeGeneral(TypedDict, total=False): + read_only: bool + + +# volume type: volume + + +class _VolumeNaturalConfig(TypedDict, total=False): + nocopy: bool + + +class _VolumeNaturalRequired(TypedDict, total=True): + type: Literal["volume"] + source: str + target: str + + +class _VolumeNatural(_VolumeNaturalRequired, _VolumeGeneral, total=False): + volume: _VolumeNaturalConfig + + +# volume type: bind + + +class _VolumeBindConfig(TypedDict, total=False): + propagation: str + + +class _VolumeBindRequired(TypedDict, total=True): + type: Literal["bind"] + source: str + target: str + + +class _VolumeBind(_VolumeBindRequired, _VolumeGeneral, total=False): + volume: _VolumeBindConfig + + +# volume type: tmpfs + + +class _VolumeTmpfsConfig(TypedDict, total=False): + size: int + "in bytes" + + +class _VolumeTmpfsRequired(TypedDict, total=True): + type: Literal["tmpfs"] + target: str + + +class _VolumeTmpfs(_VolumeTmpfsRequired, _VolumeGeneral, total=False): + tmpfs: _VolumeTmpfsConfig + + +# volume type: npipe + + +class _VolumeNpipeRequired(TypedDict, total=True): + type: Literal["npipe"] + target: str + + +class _VolumeNpipe(_VolumeNpipeRequired, _VolumeGeneral, total=False): + pass + + +# end volume types + + +_VolumeLong: TypeAlias = _VolumeNatural | _VolumeBind | _VolumeTmpfs | _VolumeNpipe + +VolumeDef: TypeAlias = _VolumeShort | _VolumeLong