defs/compose: Add typings for service volumes

main
Felix Stupp 2 years ago
parent 32c46686f6
commit 4c4c3ff15a
Signed by: zocker
GPG Key ID: 93E1BD26F6B02FB7

@ -6,6 +6,7 @@ from .service import (
ServiceName,
ContainerName,
ServiceDef as ComposeServiceDef,
VolumeDef as ComposeServiceVolumeDef,
)
from .volume import (
VolumeName,

@ -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

Loading…
Cancel
Save