Repository: gabrieldemarmiesse/python-on-whales (language: python)

Issue:
Is there a way to prevent any output from docker-compose up, build etc?
As the title suggests, I would like to prevent any output from python-on-whales.
Is there a way to do it?

Thanks!


Discussion / hints:
Currently it's only available on some commands. For exemple docker.buildx.build. I'll work on improving this area :) 
Just for my personal curiosity and also to better satisfy the request, could you tell me what's your use case? What you use python-on-whales for and why you want to supress the output?
Sorry for the delay.
It was for a univeristy project where I had to trigger many times different docker-compose files.
The CLI had a custom progress bar to show the status of the application and for this reason was better to prevent any other log.
Anyway we were able to use subprocess to do that.
Feel free to close this issue and thanks for your great work!
Thanks! I believe your use case is valid and should be in the scope of python-on-whales. I'll see what's the best way to implement it, so that the interface is intuitive!
Hi,
Dunno if should open another issue but problem is related somehow.
For my use case there is on contrary no enough output for docker compose commands.
For example when i use docker.compose.up() or pull() there is no output at all while building or downloading images.
Got some digging and it looks like docker compose is directing this output to stderr [related compose issue](https://github.com/docker/compose/issues/7346) .
I am using your library for some startup script and like it a lot.
But at first run is little sad to see nothing while 10 images are being pulled, looks kinda stuck.
Maybe there should be some flag to prevent piping/capturing std/stderr or some more control over it.
Cheers.
Thank you,  this is great feedback,  I'll look into it :) 

Fix patch:
diff --git a/python_on_whales/components/compose/cli_wrapper.py b/python_on_whales/components/compose/cli_wrapper.py
index 9577490b..626a7e44 100644
--- a/python_on_whales/components/compose/cli_wrapper.py
+++ b/python_on_whales/components/compose/cli_wrapper.py
@@ -308,7 +308,7 @@ def ps(self) -> List[python_on_whales.components.container.cli_wrapper.Container
 
     def pull(
         self,
-        services: Optional[List[str]] = None,
+        services: Union[List[str], str, None] = None,
         ignore_pull_failures: bool = False,
         include_deps: bool = False,
         quiet: bool = False,
@@ -333,6 +333,7 @@ def pull(
         if services == []:
             return
         elif services is not None:
+            services = to_list(services)
             full_cmd += services
         run(full_cmd, capture_stdout=False, capture_stderr=False)
 
@@ -570,7 +571,7 @@ def unpause(self, services: Union[str, List[str], None] = None):
 
     def up(
         self,
-        services: Optional[List[str]] = None,
+        services: Union[List[str], str, None] = None,
         build: bool = False,
         detach: bool = False,
         abort_on_container_exit: bool = False,
@@ -581,6 +582,7 @@ def up(
         color: bool = True,
         log_prefix: bool = True,
         start: bool = True,
+        quiet: bool = False,
     ):
         """Start the containers.
 
@@ -609,6 +611,8 @@ def up(
             color: If `False`, it will produce monochrome output.
             log_prefix: If `False`, will not display the prefix in the logs.
             start: Start the service after creating them.
+            quiet: By default, some progress bars and logs are sent to stderr and stdout.
+                Set `quiet=True` to avoid having any output.
 
         # Returns
             `None` at the moment. The plan is to be able to capture and stream the logs later.
@@ -631,8 +635,10 @@ def up(
         if services == []:
             return
         elif services is not None:
+            services = to_list(services)
             full_cmd += services
-        run(full_cmd, capture_stdout=False)
+        # important information is written to both stdout AND stderr.
+        run(full_cmd, capture_stdout=quiet, capture_stderr=quiet)
 
     def version(self) -> str:
         """Returns the version of docker compose as a `str`."""


Test patch:
diff --git a/tests/python_on_whales/components/my_service_build/Dockerfile b/tests/python_on_whales/components/my_service_build/Dockerfile
index b4ca998c..78c0e356 100644
--- a/tests/python_on_whales/components/my_service_build/Dockerfile
+++ b/tests/python_on_whales/components/my_service_build/Dockerfile
@@ -3,4 +3,4 @@ FROM python:3.7-slim
 RUN pip install redis
 
 RUN apt-get update && apt-get install -y iputils-ping
-CMD python -c "print(1); import time; time.sleep(99999)"
+CMD python -u -c "print(1); import time; time.sleep(99999)"
diff --git a/tests/python_on_whales/components/test_compose.py b/tests/python_on_whales/components/test_compose.py
index 855dc83a..3d3dfe8f 100644
--- a/tests/python_on_whales/components/test_compose.py
+++ b/tests/python_on_whales/components/test_compose.py
@@ -294,6 +294,7 @@ def test_docker_compose_pull():
         docker.image.remove("alpine")
     except NoSuchImage:
         pass
+    docker.compose.pull("busybox")
     docker.compose.pull(["busybox", "alpine"])
     docker.image.inspect(["busybox", "alpine"])
 
@@ -332,7 +333,7 @@ def test_docker_compose_up_abort_on_container_exit():
         ],
         compose_compatibility=True,
     )
-    docker.compose.up(["alpine"], abort_on_container_exit=True)
+    docker.compose.up("alpine", abort_on_container_exit=True)
     for container in docker.compose.ps():
         assert not container.state.running
     docker.compose.down()