Skip to content

Commit

Permalink
Merge pull request #15 from allenai/lazy-docker
Browse files Browse the repository at this point in the history
initialize Docker client lazily
  • Loading branch information
epwalsh authored Dec 9, 2021
2 parents 2785ca6 + 4948950 commit 8c46fac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Changed

- Docker Client is initialized lazily so that some functionality of `Beaker` client can be used on systems without Docker.

## [v0.2.3](https://github.com/allenai/beaker-py/releases/tag/v0.2.3) - 2021-12-09

### Fixed
Expand Down
9 changes: 8 additions & 1 deletion beaker/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Beaker:
def __init__(self, config: Config):
self.config = config
self.base_url = f"{self.config.agent_address}/api/{self.API_VERSION}"
self.docker = docker.from_env()
self._docker: Optional[docker.DockerClient] = None

@property
def user(self) -> str:
Expand All @@ -44,6 +44,13 @@ def from_env(cls, **overrides) -> "Beaker":
"""
return cls(Config.from_env(**overrides))

@property
def docker(self) -> docker.DockerClient:
if self._docker is None:
self._docker = docker.from_env()
assert self._docker is not None
return self._docker

@contextmanager
def _session_with_backoff(self) -> requests.Session:
session = requests.Session()
Expand Down

0 comments on commit 8c46fac

Please sign in to comment.