Fix all typing issues

This commit is contained in:
Ayaz Salikhov
2022-01-23 12:44:16 +03:00
parent 013a42fff3
commit 37c510fc8e
25 changed files with 184 additions and 129 deletions

View File

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