Skip to content

Commit

Permalink
added __all__ to submodules
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisTimperley committed Jun 5, 2024
1 parent 82d703f commit 3a50961
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 36 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
v0.6.2 (XXXX-XX-XX)
-------------------

* added `__all__` to all submodules to improve discoverability


v0.6.1 (2024-05-23)
--------------------

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dockerblade"
version = "0.6.1"
version = "0.6.2"
description = "Interact with Docker containers via Python-like APIs"
authors = ["Chris Timperley <[email protected]>"]
license = "Apache-2.0"
Expand Down
11 changes: 11 additions & 0 deletions src/dockerblade/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
__all__ = (
"CalledProcessError",
"CompletedProcess",
"Container",
"DockerDaemon",
"FileSystem",
"Shell",
"Stopwatch",
"exceptions",
)

from loguru import logger as _logger

from . import exceptions
Expand Down
40 changes: 23 additions & 17 deletions src/dockerblade/daemon.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
from __future__ import annotations

__all__ = ("DockerDaemon",)

from collections.abc import Mapping
from types import TracebackType
from typing import Any
import typing as t

import attr
import docker
from loguru import logger

from .container import Container
from dockerblade.container import Container

if t.TYPE_CHECKING:
from collections.abc import Mapping
from types import TracebackType



@attr.s(frozen=True)
Expand All @@ -27,7 +32,7 @@ def __attrs_post_init__(self) -> None:
object.__setattr__(self, "api", api)
logger.debug(f"created daemon connection: {self}")

def __enter__(self) -> "DockerDaemon":
def __enter__(self) -> t.Self:
return self

def __exit__(self,
Expand All @@ -51,18 +56,19 @@ def attach(self, id_or_name: str) -> Container:
logger.debug(f"attached to container [{container}]")
return container

def provision(self,
image: str,
command: str | None = None,
*,
entrypoint: str | None = None,
environment: Mapping[str, str] | None = None,
network_mode: str = "bridge",
name: str | None = None,
ports: Mapping[int, int] | None = None,
user: str | None = None,
volumes: Mapping[str, Any] | None = None,
) -> Container:
def provision(
self,
image: str,
command: str | None = None,
*,
entrypoint: str | None = None,
environment: Mapping[str, str] | None = None,
network_mode: str = "bridge",
name: str | None = None,
ports: Mapping[int, int] | None = None,
user: str | None = None,
volumes: Mapping[str, t.Any] | None = None,
) -> Container:
"""Creates a Docker container from a given image.
Arguments:
Expand Down
20 changes: 18 additions & 2 deletions src/dockerblade/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
from __future__ import annotations

__all__ = (
"DockerBladeException",
"UnexpectedError",
"EnvNotFoundError",
"CopyFailed",
"IsADirectoryError",
"DirectoryNotEmpty",
"IsNotADirectoryError",
"HostFileNotFound",
"ContainerFileNotFound",
"ContainerFileAlreadyExists",
"CalledProcessError",
"TimeoutExpired",
)

import subprocess as _subprocess
import typing as _t

import attr as _attr

Expand All @@ -12,7 +28,7 @@ class DockerBladeException(Exception):
class UnexpectedError(DockerBladeException):
"""An unexpected error occurred during an operation."""
description: str
error: _t.Optional["CalledProcessError"] = _attr.ib(default=None)
error: CalledProcessError | None = _attr.ib(default=None)

def __str__(self) -> str:
msg = f"An unexpected error occurred: {self.description}"
Expand Down
17 changes: 10 additions & 7 deletions src/dockerblade/files.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
from __future__ import annotations

__all__ = ("FileSystem",)

import contextlib
import os
import subprocess
import tempfile
import typing
from collections.abc import Iterator
from pathlib import Path
from subprocess import DEVNULL
from typing import Literal, overload

import attr
from loguru import logger

from . import exceptions as exc
from .util import quote_container, quote_host
import dockerblade.exceptions as exc
from dockerblade.util import quote_container, quote_host

if typing.TYPE_CHECKING:
from .container import Container
from .shell import Shell
from collections.abc import Iterator

from dockerblade.container import Container
from dockerblade.shell import Shell

_ON_WINDOWS = os.name == "nt"

Expand All @@ -36,8 +39,8 @@ class FileSystem:
container: Container
The container to which this filesystem belongs.
"""
container: "Container" = attr.ib()
_shell: "Shell" = attr.ib(repr=False, eq=False, hash=False)
container: Container = attr.ib()
_shell: Shell = attr.ib(repr=False, eq=False, hash=False)

def copy_from_host(self, path_host: str, path_container: str) -> None:
"""Copies a given file or directory tree from the host to the container.
Expand Down
10 changes: 8 additions & 2 deletions src/dockerblade/shell.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
__all__ = ("Shell", "CompletedProcess", "CalledProcessError")
from __future__ import annotations

__all__ = (
"CalledProcessError",
"CompletedProcess",
"Shell",
)

import typing as t
from pathlib import Path
Expand Down Expand Up @@ -77,7 +83,7 @@ class Shell:
ContainerFileNotFound
If a given source file is not found.
"""
container: "Container" = attr.ib()
container: Container = attr.ib()
path: str = attr.ib()
_sources: t.Sequence[str] = attr.ib(factory=tuple)
_environment: t.Mapping[str, str] = attr.ib(factory=dict)
Expand Down
20 changes: 13 additions & 7 deletions src/dockerblade/stopwatch.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
from __future__ import annotations

__all__ = ("Stopwatch",)

import typing as t
import warnings
from timeit import default_timer as timer
from types import TracebackType

import attr

if t.TYPE_CHECKING:
from types import TracebackType


@attr.s(slots=True, repr=False, str=False, eq=False, hash=False)
class Stopwatch:
Expand All @@ -22,15 +27,16 @@ class Stopwatch:
_paused: bool = attr.ib(default=True)
_time_start: float = attr.ib(default=0.0)

def __enter__(self) -> "Stopwatch":
def __enter__(self) -> t.Self:
self.start()
return self

def __exit__(self,
ex_type: type[BaseException] | None,
ex_val: BaseException | None,
ex_tb: TracebackType | None,
) -> None:
def __exit__(
self,
ex_type: type[BaseException] | None,
ex_val: BaseException | None,
ex_tb: TracebackType | None,
) -> None:
self.stop()

def __repr__(self) -> str:
Expand Down
1 change: 1 addition & 0 deletions src/dockerblade/version.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
__all__ = ("__version__",)
__version__ = "0.6.1"

0 comments on commit 3a50961

Please sign in to comment.