Skip to content

Commit ee010cd

Browse files
author
Gustavo Narea
committed
Output docker-compose up to stdout without buffering
1 parent 34faacd commit ee010cd

4 files changed

Lines changed: 26 additions & 8 deletions

File tree

VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0a2
1+
1.0a3

docker_dev/docker_interface.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,18 @@ def run_docker_compose_subcommand(
2121
subcommand_name,
2222
subcommand_args,
2323
docker_compose_file_path,
24-
project_name
24+
project_name,
25+
return_stdout=True,
2526
):
2627
project_file_arg = '--file={}'.format(docker_compose_file_path)
2728
command_args = [project_file_arg, subcommand_name] + subcommand_args
2829
command_environ = {'COMPOSE_PROJECT_NAME': project_name}
29-
output = run_command('docker-compose', command_args, command_environ)
30+
output = run_command(
31+
'docker-compose',
32+
command_args,
33+
command_environ,
34+
return_stdout,
35+
)
3036
return output
3137

3238

docker_dev/projects.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def run_project(docker_compose_file_path, project_name):
4949
['--force-recreate', '--abort-on-container-exit'],
5050
docker_compose_file_path,
5151
project_name,
52+
return_stdout=False,
5253
)
5354

5455

docker_dev/subprocess.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
# INFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE.
1414
#
1515
##############################################################################
16+
from io import BytesIO
1617
from locale import getpreferredencoding
1718
from os import environ
18-
from subprocess import CalledProcessError
19-
from subprocess import check_output
19+
from subprocess import CalledProcessError, check_call
20+
from sys import stdout
2021
from tempfile import TemporaryFile
2122

2223
from docker_dev.exceptions import SubprocessError, \
@@ -26,15 +27,23 @@
2627
_SYSTEM_ENCODING = getpreferredencoding()
2728

2829

29-
def run_command(command_name, command_args, additional_environ=None, **kwargs):
30+
def run_command(
31+
command_name,
32+
command_args,
33+
additional_environ=None,
34+
return_stdout=True,
35+
**kwargs
36+
):
3037
command_parts = [command_name] + command_args
3138
additional_environ = additional_environ or {}
3239
command_environ = dict(additional_environ, PATH=environ['PATH'])
40+
command_stdout = BytesIO() if return_stdout else stdout
3341
command_stderr = TemporaryFile()
3442
try:
35-
command_stdout_bytes = check_output(
43+
check_call(
3644
command_parts,
3745
env=command_environ,
46+
stdout=command_stdout,
3847
stderr=command_stderr,
3948
**kwargs
4049
)
@@ -47,6 +56,8 @@ def run_command(command_name, command_args, additional_environ=None, **kwargs):
4756
)
4857
except FileNotFoundError:
4958
raise MissingCommandError(command_name)
50-
else:
59+
60+
if return_stdout:
61+
command_stdout_bytes = command_stdout.getvalue()
5162
command_stdout_str = command_stdout_bytes.decode(_SYSTEM_ENCODING)
5263
return command_stdout_str.rstrip()

0 commit comments

Comments
 (0)