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

Issue:
compose down --volumes
Hello,
I would like to ask you to introduce the support for the `--volumes` flag in compose down

If you need a testing strategy I can work on a minimal example to be used as test case

Thank you again!



Discussion / hints:
Thank for your issues! I'll try to implement them when I have some time. Worst case scénario, during my holidays first week of october

Fix patch:
diff --git a/python_on_whales/components/compose/cli_wrapper.py b/python_on_whales/components/compose/cli_wrapper.py
index f0e5d15f..8c4095f0 100644
--- a/python_on_whales/components/compose/cli_wrapper.py
+++ b/python_on_whales/components/compose/cli_wrapper.py
@@ -82,6 +82,7 @@ def down(
         remove_orphans: bool = False,
         remove_images: Optional[str] = None,
         timeout: Optional[int] = None,
+        volumes: bool = False,
     ):
         """Stops and removes the containers
 
@@ -92,11 +93,16 @@ def down(
                 `"local"` remove only images that don't have a custom
                 tag. Possible values are `"local"` and `"all"`.
             timeout: Specify a shutdown timeout in seconds (default 10).
+            volumes: Remove named volumes declared in the
+                volumes section of the Compose file and anonymous
+                volumes attached to containers.
         """
         full_cmd = self.docker_compose_cmd + ["down"]
         full_cmd.add_flag("--remove-orphans", remove_orphans)
         full_cmd.add_simple_arg("--rmi", remove_images)
         full_cmd.add_simple_arg("--timeout", timeout)
+        full_cmd.add_flag("--volumes", volumes)
+
         run(full_cmd)
 
     def events(self):


Test patch:
diff --git a/tests/python_on_whales/components/complexe-compose.yml b/tests/python_on_whales/components/complexe-compose.yml
index 28573b4f..24a0f62b 100644
--- a/tests/python_on_whales/components/complexe-compose.yml
+++ b/tests/python_on_whales/components/complexe-compose.yml
@@ -5,7 +5,7 @@ services:
     build:
       context: my_service_build
     image: some_random_image
-    command: ping -c 7 www.google.com
+    command: ping -c 2 www.google.com
     ports:
      - "5000:5000"
     volumes:
diff --git a/tests/python_on_whales/components/my_service_build/Dockerfile b/tests/python_on_whales/components/my_service_build/Dockerfile
index 445932d1..b4ca998c 100644
--- a/tests/python_on_whales/components/my_service_build/Dockerfile
+++ b/tests/python_on_whales/components/my_service_build/Dockerfile
@@ -2,4 +2,5 @@ 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)"
diff --git a/tests/python_on_whales/components/test_compose.py b/tests/python_on_whales/components/test_compose.py
index a592ef9e..8eb7a640 100644
--- a/tests/python_on_whales/components/test_compose.py
+++ b/tests/python_on_whales/components/test_compose.py
@@ -230,7 +230,7 @@ def test_config_complexe_compose():
     assert config.services["my_service"].command == [
         "ping",
         "-c",
-        "7",
+        "2",
         "www.google.com",
     ]
 
@@ -259,6 +259,21 @@ def test_config_complexe_compose():
     assert not config.volumes["dodo"].external
 
 
+def test_compose_down_volumes():
+    compose_file = (
+        PROJECT_ROOT / "tests/python_on_whales/components/complexe-compose.yml"
+    )
+    docker = DockerClient(compose_files=[compose_file])
+    docker.compose.up(
+        ["my_service"], detach=True, scales=dict(my_service=1), build=True
+    )
+    assert docker.volume.exists("components_dodo")
+    docker.compose.down()
+    assert docker.volume.exists("components_dodo")
+    docker.compose.down(volumes=True)
+    assert not docker.volume.exists("components_dodo")
+
+
 def test_compose_config_from_rc1():
     config = ComposeConfig.parse_file(
         Path(__file__).parent / "strange_compose_config_rc1.json"