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

Issue:
Docker compose scale will never exist
Hello,
I was looking at the scale command and found some ambiguities

Here:
https://gabrieldemarmiesse.github.io/python-on-whales/sub-commands/compose/#scale

docker compose scale is reported as `Not yet implemented` but this command will never exist in compose-cli because it is deprecated in docker-compose

here in compose-cli (command not found)
```
$ docker compose scale

Usage:  docker compose [OPTIONS] COMMAND
[...]
unknown docker command: "compose scale"

```

here in docker-compose (deprecated in favor of --scale flag on up)
```
$ docker-compose scale --help
Set number of containers to run for a service.

Numbers are specified in the form service=num as arguments.
For example:

    $ docker-compose scale web=2 worker=3

This command is deprecated. Use the up command with the --scale flag
instead.

Usage: scale [options] [SERVICE=NUM...]

Options:
  -t, --timeout TIMEOUT      Specify a shutdown timeout in seconds.
                             (default: 10)
```

The lack of support of the scale command in compose-cli is also confirmed here: https://github.com/docker/compose-cli/issues/1366

So I think that compose scale should be removed from the docs of python on whales instead of being reported as not implemented yet.

In addition, the scale option should be added to compose up 


Discussion / hints:
Thanks for the report, that wasn't clear to be at all! I'll make the changes.

Fix patch:
diff --git a/python_on_whales/components/compose/cli_wrapper.py b/python_on_whales/components/compose/cli_wrapper.py
index 2c4a669c..ffcb21f5 100644
--- a/python_on_whales/components/compose/cli_wrapper.py
+++ b/python_on_whales/components/compose/cli_wrapper.py
@@ -213,10 +213,6 @@ def run(self):
         """Not yet implemented"""
         raise NotImplementedError
 
-    def scale(self):
-        """Not yet implemented"""
-        raise NotImplementedError
-
     def start(self):
         """Not yet implemented"""
         raise NotImplementedError
@@ -257,6 +253,7 @@ def up(
         build: bool = False,
         detach: bool = False,
         abort_on_container_exit: bool = False,
+        scales: Dict[str, int] = {},
     ):
         """Start the containers.
 
@@ -274,6 +271,9 @@ def up(
                 Incompatible with `abort_on_container_exit=True`.
             abort_on_container_exit: If `True` stops all containers if any container was
                 stopped. Incompatible with `detach=True`.
+            scales: Scale SERVICE to NUM instances. Overrides
+                the scale setting in the Compose file if present. For example:
+                `scales={"my_service": 2, "my_other_service": 5}`.
 
         # Returns
             `None` at the moment. The plan is to be able to capture and stream the logs later.
@@ -284,6 +284,8 @@ def up(
         full_cmd.add_flag("--detach", detach)
         full_cmd.add_flag("--build", build)
         full_cmd.add_flag("--abort-on-container-exit", abort_on_container_exit)
+        for service, scale in scales.items():
+            full_cmd.add_simple_arg("--scale", f"{service}={scale}")
 
         full_cmd += services
         run(full_cmd, capture_stdout=False)


Test patch:
diff --git a/tests/python_on_whales/components/test_compose.py b/tests/python_on_whales/components/test_compose.py
index 089b8ead..48072de0 100644
--- a/tests/python_on_whales/components/test_compose.py
+++ b/tests/python_on_whales/components/test_compose.py
@@ -46,6 +46,24 @@ def test_docker_compose_up_detach_down():
     docker.compose.down()
 
 
+def test_docker_compose_up_detach_down_with_scales():
+    docker.compose.up(
+        ["my_service", "busybox", "alpine"],
+        detach=True,
+        scales={"busybox": 2, "alpine": 3},
+    )
+    assert len(docker.compose.ps()) == 6
+
+    docker.compose.up(
+        ["my_service", "busybox", "alpine"],
+        detach=True,
+        scales={"busybox": 2, "alpine": 5},
+    )
+    assert len(docker.compose.ps()) == 8
+
+    docker.compose.down(timeout=1)
+
+
 def test_docker_compose_pause_unpause():
     docker.compose.up(["my_service", "busybox", "alpine"], detach=True)
     docker.compose.pause()