mirror of
https://github.com/jupyter/docker-stacks.git
synced 2025-10-10 19:42:58 +00:00
Fix all typing issues
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# Copyright (c) Jupyter Development Team.
|
||||
# Distributed under the terms of the Modified BSD License.
|
||||
from typing import Optional
|
||||
from types import TracebackType
|
||||
import docker
|
||||
from docker.models.containers import Container
|
||||
import logging
|
||||
@@ -13,7 +14,7 @@ class DockerRunner:
|
||||
def __init__(
|
||||
self,
|
||||
image_name: str,
|
||||
docker_client=docker.from_env(),
|
||||
docker_client: docker.DockerClient = docker.from_env(),
|
||||
command: str = "sleep infinity",
|
||||
):
|
||||
self.container: Optional[Container] = None
|
||||
@@ -31,7 +32,13 @@ class DockerRunner:
|
||||
LOGGER.info(f"Container {self.container.name} created")
|
||||
return self.container
|
||||
|
||||
def __exit__(self, exc_type, exc_value, traceback) -> None:
|
||||
def __exit__(
|
||||
self,
|
||||
exc_type: Optional[type[BaseException]],
|
||||
exc_val: Optional[BaseException],
|
||||
exc_tb: Optional[TracebackType],
|
||||
) -> None:
|
||||
assert self.container is not None
|
||||
LOGGER.info(f"Removing container {self.container.name} ...")
|
||||
if self.container:
|
||||
self.container.remove(force=True)
|
||||
@@ -44,6 +51,7 @@ class DockerRunner:
|
||||
LOGGER.info(f"Running cmd: '{cmd}' on container: {container}")
|
||||
out = container.exec_run(cmd)
|
||||
result = out.output.decode("utf-8").rstrip()
|
||||
assert isinstance(result, str)
|
||||
if print_result:
|
||||
LOGGER.info(f"Command result: {result}")
|
||||
assert out.exit_code == 0, f"Command: {cmd} failed"
|
||||
|
Reference in New Issue
Block a user