Skip to content

Commit 2b2037e

Browse files
authored
Add logging, remove crayon and blindspin (#112)
* add logging, remove crayon and blindspin * remove example and lint * use standard approach for logging
1 parent 7d8a9f8 commit 2b2037e

File tree

9 files changed

+55
-68
lines changed

9 files changed

+55
-68
lines changed

requirements/3.5.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@ alabaster==0.7.12 # via sphinx
99
attrs==19.3.0 # via jsonschema, pytest
1010
babel==2.8.0 # via sphinx
1111
bcrypt==3.1.7 # via paramiko
12-
blindspin==2.0.1 # via testcontainers
1312
cached-property==1.5.1 # via docker-compose
1413
cachetools==4.1.1 # via google-auth
1514
certifi==2020.6.20 # via requests
1615
cffi==1.14.2 # via bcrypt, cryptography, pynacl
1716
chardet==3.0.4 # via requests
1817
codecov==2.1.8 # via -r requirements.in
19-
colorama==0.4.3 # via crayons
2018
coverage==5.2.1 # via codecov, pytest-cov
21-
crayons==0.3.1 # via testcontainers
2219
cryptography==3.0 # via paramiko
2320
cx-oracle==8.0.0 # via testcontainers
2421
deprecation==2.1.0 # via testcontainers

requirements/3.6.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@ alabaster==0.7.12 # via sphinx
99
attrs==19.3.0 # via jsonschema, pytest
1010
babel==2.8.0 # via sphinx
1111
bcrypt==3.2.0 # via paramiko
12-
blindspin==2.0.1 # via testcontainers
1312
cached-property==1.5.1 # via docker-compose
1413
cachetools==4.1.1 # via google-auth
1514
certifi==2020.6.20 # via requests
1615
cffi==1.14.2 # via bcrypt, cryptography, pynacl
1716
chardet==3.0.4 # via requests
1817
codecov==2.1.8 # via -r requirements.in
19-
colorama==0.4.3 # via crayons
2018
coverage==5.2.1 # via codecov, pytest-cov
21-
crayons==0.3.1 # via testcontainers
2219
cryptography==3.0 # via paramiko
2320
cx-oracle==8.0.0 # via testcontainers
2421
deprecation==2.1.0 # via testcontainers

requirements/3.7.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@ alabaster==0.7.12 # via sphinx
99
attrs==19.3.0 # via jsonschema, pytest
1010
babel==2.8.0 # via sphinx
1111
bcrypt==3.2.0 # via paramiko
12-
blindspin==2.0.1 # via testcontainers
1312
cached-property==1.5.1 # via docker-compose
1413
cachetools==4.1.1 # via google-auth
1514
certifi==2020.6.20 # via requests
1615
cffi==1.14.2 # via bcrypt, cryptography, pynacl
1716
chardet==3.0.4 # via requests
1817
codecov==2.1.8 # via -r requirements.in
19-
colorama==0.4.3 # via crayons
2018
coverage==5.2.1 # via codecov, pytest-cov
21-
crayons==0.3.1 # via testcontainers
2219
cryptography==3.0 # via paramiko
2320
cx-oracle==8.0.0 # via testcontainers
2421
deprecation==2.1.0 # via testcontainers

requirements/3.8.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@ alabaster==0.7.12 # via sphinx
99
attrs==19.3.0 # via jsonschema, pytest
1010
babel==2.8.0 # via sphinx
1111
bcrypt==3.2.0 # via paramiko
12-
blindspin==2.0.1 # via testcontainers
1312
cached-property==1.5.1 # via docker-compose
1413
cachetools==4.1.1 # via google-auth
1514
certifi==2020.6.20 # via requests
1615
cffi==1.14.2 # via bcrypt, cryptography, pynacl
1716
chardet==3.0.4 # via requests
1817
codecov==2.1.8 # via -r requirements.in
19-
colorama==0.4.3 # via crayons
2018
coverage==5.2.1 # via codecov, pytest-cov
21-
crayons==0.3.1 # via testcontainers
2219
cryptography==3.0 # via paramiko
2320
cx-oracle==8.0.0 # via testcontainers
2421
deprecation==2.1.0 # via testcontainers

setup.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@
4444
install_requires=[
4545
'docker',
4646
'wrapt',
47-
'crayons',
48-
'blindspin',
4947
'deprecation',
5048
],
5149
extras_require={

testcontainers/compose.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import subprocess
99

10-
import blindspin
1110
import requests
1211

1312
from testcontainers.core.waiting_utils import wait_container_is_ready
@@ -81,28 +80,25 @@ def docker_compose_command(self):
8180
return docker_compose_cmd
8281

8382
def start(self):
84-
with blindspin.spinner():
85-
if self.pull:
86-
pull_cmd = self.docker_compose_command() + ['pull']
87-
subprocess.call(pull_cmd, cwd=self.filepath)
88-
up_cmd = self.docker_compose_command() + ['up', '-d']
89-
subprocess.call(up_cmd, cwd=self.filepath)
83+
if self.pull:
84+
pull_cmd = self.docker_compose_command() + ['pull']
85+
subprocess.call(pull_cmd, cwd=self.filepath)
86+
up_cmd = self.docker_compose_command() + ['up', '-d']
87+
subprocess.call(up_cmd, cwd=self.filepath)
9088

9189
def stop(self):
92-
with blindspin.spinner():
93-
down_cmd = self.docker_compose_command() + ['down', '-v']
94-
subprocess.call(down_cmd, cwd=self.filepath)
90+
down_cmd = self.docker_compose_command() + ['down', '-v']
91+
subprocess.call(down_cmd, cwd=self.filepath)
9592

9693
def get_logs(self):
9794
logs_cmd = self.docker_compose_command() + ["logs"]
98-
with blindspin.spinner():
99-
result = subprocess.run(
100-
logs_cmd,
101-
cwd=self.filepath,
102-
stdout=subprocess.PIPE,
103-
stderr=subprocess.PIPE,
104-
)
105-
return result.stdout, result.stderr
95+
result = subprocess.run(
96+
logs_cmd,
97+
cwd=self.filepath,
98+
stdout=subprocess.PIPE,
99+
stderr=subprocess.PIPE,
100+
)
101+
return result.stdout, result.stderr
106102

107103
def get_service_port(self, service_name, port):
108104
return self._get_service_info(service_name, port)[1]

testcontainers/core/container.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import blindspin
2-
import crayons
31
from docker.models.containers import Container
42

53
from testcontainers.core.docker_client import DockerClient
64
from testcontainers.core.exceptions import ContainerStartException
7-
from testcontainers.core.utils import inside_container
5+
from testcontainers.core.utils import setup_logger, inside_container
6+
7+
logger = setup_logger(__name__)
88

99

1010
class DockerContainer(object):
@@ -38,23 +38,18 @@ def with_kargs(self, **kargs) -> 'DockerContainer':
3838
return self
3939

4040
def start(self):
41-
print("")
42-
print("{} {}".format(crayons.yellow("Pulling image"),
43-
crayons.red(self.image)))
44-
with blindspin.spinner():
45-
docker_client = self.get_docker_client()
46-
self._container = docker_client.run(self.image,
47-
command=self._command,
48-
detach=True,
49-
environment=self.env,
50-
ports=self.ports,
51-
name=self._name,
52-
volumes=self.volumes,
53-
**self._kargs
54-
)
55-
print("")
56-
print("Container started: ",
57-
crayons.yellow(self._container.short_id, bold=True))
41+
logger.info("Pulling image %s", self.image)
42+
docker_client = self.get_docker_client()
43+
self._container = docker_client.run(self.image,
44+
command=self._command,
45+
detach=True,
46+
environment=self.env,
47+
ports=self.ports,
48+
name=self._name,
49+
volumes=self.volumes,
50+
**self._kargs
51+
)
52+
logger.info("Container started: %s", self._container.short_id)
5853
return self
5954

6055
def stop(self, force=True, delete_volume=True):

testcontainers/core/utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
import os
22
import sys
33
import subprocess
4+
import logging
45

56
LINUX = "linux"
67
MAC = "mac"
78
WIN = "win"
89

910

11+
def setup_logger(name):
12+
logger = logging.getLogger(name)
13+
logger.setLevel(logging.INFO)
14+
handler = logging.StreamHandler()
15+
handler.setLevel(logging.INFO)
16+
logger.addHandler(handler)
17+
return logger
18+
19+
1020
def os_name():
1121
pl = sys.platform
1222
if pl == "linux" or pl == "linux2":

testcontainers/core/waiting_utils.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
import re
1616
import time
1717

18-
import blindspin
19-
import crayons
2018
import wrapt
2119

2220
from testcontainers.core import config
2321
from testcontainers.core.exceptions import TimeoutException
22+
from testcontainers.core.utils import setup_logger
23+
24+
logger = setup_logger(__name__)
2425

2526

2627
def wait_container_is_ready():
@@ -35,20 +36,19 @@ def wait_container_is_ready():
3536
@wrapt.decorator
3637
def wrapper(wrapped, instance, args, kwargs):
3738
exception = None
38-
print(crayons.yellow("Waiting to be ready..."))
39-
with blindspin.spinner():
40-
for _ in range(0, config.MAX_TRIES):
41-
try:
42-
return wrapped(*args, **kwargs)
43-
except Exception as e:
44-
time.sleep(config.SLEEP_TIME)
45-
exception = e
46-
raise TimeoutException(
47-
"""Wait time exceeded {0} sec.
48-
Method {1}, args {2} , kwargs {3}.
49-
Exception {4}""".format(config.MAX_TRIES,
50-
wrapped.__name__,
51-
args, kwargs, exception))
39+
logger.info("Waiting to be ready...")
40+
for _ in range(0, config.MAX_TRIES):
41+
try:
42+
return wrapped(*args, **kwargs)
43+
except Exception as e:
44+
time.sleep(config.SLEEP_TIME)
45+
exception = e
46+
raise TimeoutException(
47+
"""Wait time exceeded {0} sec.
48+
Method {1}, args {2} , kwargs {3}.
49+
Exception {4}""".format(config.MAX_TRIES,
50+
wrapped.__name__,
51+
args, kwargs, exception))
5252

5353
return wrapper
5454

0 commit comments

Comments
 (0)