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

Issue:
Support for compse up --renew-anon-volumes
Hello, thanks for the great module. Will it be possible to add support for the `--renew-anon-volumes` parameter to `docker compose up`. See [up options docs](https://docs.docker.com/engine/reference/commandline/compose_up/#options)


Discussion / hints:
Sure thing! I'm open to pull requests too if you have the time :) otherwise, I'll implement it when I can
Sure, will submit one shortly. Thanks!

Fix patch:
diff --git a/python_on_whales/components/compose/cli_wrapper.py b/python_on_whales/components/compose/cli_wrapper.py
index 43cebac0..f68466bb 100644
--- a/python_on_whales/components/compose/cli_wrapper.py
+++ b/python_on_whales/components/compose/cli_wrapper.py
@@ -669,6 +669,7 @@ def up(
         recreate: bool = True,
         no_build: bool = False,
         remove_orphans: bool = False,
+        renew_anon_volumes: bool = False,
         color: bool = True,
         log_prefix: bool = True,
         start: bool = True,
@@ -704,6 +705,8 @@ def up(
                 `recreate=False` and `force_recreate=True` are incompatible.
             no_build: Don't build an image, even if it's missing.
             remove_orphans: Remove containers for services not defined in the Compose file.
+            renew_anon_volumes: Recreate anonymous volumes instead of retrieving
+                data from the previous containers.
             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.
@@ -733,6 +736,7 @@ def up(
         full_cmd.add_flag("--no-log-prefix", not log_prefix)
         full_cmd.add_flag("--no-start", not start)
         full_cmd.add_flag("--remove-orphans", remove_orphans)
+        full_cmd.add_flag("--renew-anon-volumes", renew_anon_volumes)
         full_cmd.add_simple_arg("--pull", pull)
 
         if no_attach_services is not None:


Test patch:
diff --git a/tests/python_on_whales/components/compose_anon_volumes.yml b/tests/python_on_whales/components/compose_anon_volumes.yml
new file mode 100644
index 00000000..0b121fcc
--- /dev/null
+++ b/tests/python_on_whales/components/compose_anon_volumes.yml
@@ -0,0 +1,8 @@
+version: "3.9"
+
+services:
+  busybox:
+    image: busybox:latest
+    command: sleep infinity
+    volumes:
+      - /hello-volume
diff --git a/tests/python_on_whales/components/test_compose.py b/tests/python_on_whales/components/test_compose.py
index 7e09b6a8..5b8b0a33 100644
--- a/tests/python_on_whales/components/test_compose.py
+++ b/tests/python_on_whales/components/test_compose.py
@@ -740,6 +740,42 @@ def test_compose_multiple_profiles():
     docker.compose.down(timeout=1)
 
 
+def test_compose_anon_volumes_recreate_not_enabled():
+    docker = DockerClient(
+        compose_files=[
+            PROJECT_ROOT / "tests/python_on_whales/components/compose_anon_volumes.yml"
+        ],
+    )
+    docker.compose.up(detach=True)
+
+    volume_name_before_recreate = docker.compose.ps()[0].mounts[0].name
+
+    docker.compose.up(detach=True, force_recreate=True)
+    volumes_name_after_recreate = docker.compose.ps()[0].mounts[0].name
+
+    assert volume_name_before_recreate == volumes_name_after_recreate
+
+    docker.compose.down(timeout=1)
+
+
+def test_compose_anon_volumes_recreate_enabled():
+    docker = DockerClient(
+        compose_files=[
+            PROJECT_ROOT / "tests/python_on_whales/components/compose_anon_volumes.yml"
+        ],
+    )
+    docker.compose.up(detach=True)
+
+    volume_name_before_recreate = docker.compose.ps()[0].mounts[0].name
+
+    docker.compose.up(detach=True, force_recreate=True, renew_anon_volumes=True)
+    volumes_name_after_recreate = docker.compose.ps()[0].mounts[0].name
+
+    assert volume_name_before_recreate != volumes_name_after_recreate
+
+    docker.compose.down(timeout=1)
+
+
 def test_compose_port():
     d = DockerClient(
         compose_files=[