Skip to content

ccproxy.docker.docker_path

ccproxy.docker.docker_path

Docker path management with clean API.

DockerPath

Bases: BaseModel

Represents a mapping between host and container paths.

Provides a clean API for Docker volume mounting and path resolution.

Example

workspace = DockerPath(host_path="/some/host/local/path", container_path="/tmp/docker/workspace") docker_vol = workspace.vol() # Returns volume mapping tuple container_path = workspace.container() # Returns container path host_path = workspace.host() # Returns host path

vol

vol()

Get Docker volume mapping tuple.

Returns:

Type Description
tuple[str, str]

tuple[str, str]: (host_path, container_path) for Docker -v flag

Source code in ccproxy/docker/docker_path.py
def vol(self) -> tuple[str, str]:
    """Get Docker volume mapping tuple.

    Returns:
        tuple[str, str]: (host_path, container_path) for Docker -v flag
    """
    if self.host_path is None:
        raise ValueError("host_path is not set, cannot create volume mapping")
    return (str(self.host_path), self.container_path)

host

host()

Get host path as Path object.

Returns:

Name Type Description
Path Path

Resolved host path

Source code in ccproxy/docker/docker_path.py
def host(self) -> Path:
    """Get host path as Path object.

    Returns:
        Path: Resolved host path
    """
    if self.host_path is None:
        raise ValueError("host_path is not set")
    return self.host_path

container

container()

Get container path as string.

Returns:

Name Type Description
str str

Container path

Source code in ccproxy/docker/docker_path.py
def container(self) -> str:
    """Get container path as string.

    Returns:
        str: Container path
    """
    return self.container_path

join

join(*subpaths)

Create new DockerPath with subpaths joined to both host and container paths.

Parameters:

Name Type Description Default
*subpaths str

Path components to join

()

Returns:

Name Type Description
DockerPath DockerPath

New instance with joined paths

Source code in ccproxy/docker/docker_path.py
def join(self, *subpaths: str) -> "DockerPath":
    """Create new DockerPath with subpaths joined to both host and container paths.

    Args:
        *subpaths: Path components to join

    Returns:
        DockerPath: New instance with joined paths
    """
    host_joined = self.host_path
    if host_joined:
        for subpath in subpaths:
            host_joined = host_joined / subpath

    container_joined = self.container_path
    for subpath in subpaths:
        container_joined = f"{container_joined}/{subpath}".replace("//", "/")

    return DockerPath(host_path=host_joined, container_path=container_joined)

DockerPathSet

DockerPathSet(base_host_path=None)

Collection of named Docker paths for organized path management.

Example

paths = DockerPathSet("/tmp/build") paths.add("workspace", "/workspace") paths.add("config", "/workspace/config")

workspace_vol = paths.get("workspace").vol() config_path = paths.get("config").container()

Parameters:

Name Type Description Default
base_host_path str | Path | None

Base path on host for all paths in this set

None
Source code in ccproxy/docker/docker_path.py
def __init__(self, base_host_path: str | Path | None = None) -> None:
    """Initialize Docker path set.

    Args:
        base_host_path: Base path on host for all paths in this set
    """
    self.base_host_path = Path(base_host_path).resolve() if base_host_path else None
    self.paths: dict[str, DockerPath] = {}
    self.logger = get_logger(f"{__name__}.{self.__class__.__name__}")

add

add(name, container_path, host_subpath=None)

Add a named Docker path to the set.

Parameters:

Name Type Description Default
name str

Logical name for the path

required
container_path str

Path inside the Docker container

required
host_subpath str | None

Optional subpath from base_host_path, defaults to name

None

Returns:

Name Type Description
Self Self

For method chaining

Source code in ccproxy/docker/docker_path.py
def add(
    self, name: str, container_path: str, host_subpath: str | None = None
) -> Self:
    """Add a named Docker path to the set.

    Args:
        name: Logical name for the path
        container_path: Path inside the Docker container
        host_subpath: Optional subpath from base_host_path, defaults to name

    Returns:
        Self: For method chaining
    """
    if self.base_host_path is None:
        raise ValueError("base_host_path must be set to use add() method")

    if host_subpath is None:
        host_subpath = name

    # Handle empty string to mean no subpath (use base path directly)
    if host_subpath == "":
        host_path = self.base_host_path
    else:
        host_path = self.base_host_path / host_subpath

    self.paths[name] = DockerPath(
        host_path=host_path, container_path=container_path
    )
    return self

add_path

add_path(name, docker_path)

Add a pre-created DockerPath to the set.

Parameters:

Name Type Description Default
name str

Logical name for the path

required
docker_path DockerPath

DockerPath instance to add

required

Returns:

Name Type Description
Self Self

For method chaining

Source code in ccproxy/docker/docker_path.py
def add_path(self, name: str, docker_path: DockerPath) -> Self:
    """Add a pre-created DockerPath to the set.

    Args:
        name: Logical name for the path
        docker_path: DockerPath instance to add

    Returns:
        Self: For method chaining
    """
    self.paths[name] = docker_path
    return self

get

get(name)

Get Docker path by name.

Parameters:

Name Type Description Default
name str

Logical name of the path

required

Returns:

Name Type Description
DockerPath DockerPath

The Docker path instance

Raises:

Type Description
KeyError

If path name is not found

Source code in ccproxy/docker/docker_path.py
def get(self, name: str) -> DockerPath:
    """Get Docker path by name.

    Args:
        name: Logical name of the path

    Returns:
        DockerPath: The Docker path instance

    Raises:
        KeyError: If path name is not found
    """
    if name not in self.paths:
        raise KeyError(
            f"Docker path '{name}' not found. Available: {list(self.paths.keys())}"
        )
    return self.paths[name]

has

has(name)

Check if a path name exists in the set.

Parameters:

Name Type Description Default
name str

Logical name to check

required

Returns:

Name Type Description
bool bool

True if path exists

Source code in ccproxy/docker/docker_path.py
def has(self, name: str) -> bool:
    """Check if a path name exists in the set.

    Args:
        name: Logical name to check

    Returns:
        bool: True if path exists
    """
    return name in self.paths

volumes

volumes()

Get all volume mappings for Docker.

Returns:

Type Description
list[tuple[str, str]]

list[tuple[str, str]]: List of (host_path, container_path) tuples

Source code in ccproxy/docker/docker_path.py
def volumes(self) -> list[tuple[str, str]]:
    """Get all volume mappings for Docker.

    Returns:
        list[tuple[str, str]]: List of (host_path, container_path) tuples
    """
    return [path.vol() for path in self.paths.values()]

names

names()

Get all path names in the set.

Returns:

Type Description
list[str]

list[str]: List of logical path names

Source code in ccproxy/docker/docker_path.py
def names(self) -> list[str]:
    """Get all path names in the set.

    Returns:
        list[str]: List of logical path names
    """
    return list(self.paths.keys())