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

Issue:
Docker Compose run --build
Is there a reason why `compose.run` does not have a build flag?  

It is in the docs: https://docs.docker.com/engine/reference/commandline/compose_run/#options

I would be willing to make a pr if welcome


Discussion / hints:
A PR is welcome. Our ci has some issues right now that I'm fixing, but you can still open PRs

Fix patch:
diff --git a/python_on_whales/components/compose/cli_wrapper.py b/python_on_whales/components/compose/cli_wrapper.py
index 770e8d53..8ad1ef80 100644
--- a/python_on_whales/components/compose/cli_wrapper.py
+++ b/python_on_whales/components/compose/cli_wrapper.py
@@ -499,6 +499,7 @@ def run(
         self,
         service: str,
         command: List[str] = [],
+        build: bool = False,
         detach: bool = False,
         # entrypoint: Optional[List[str]] = None,
         # envs: Dict[str, str] = {},
@@ -563,6 +564,7 @@ def run(
                 "Try setting tty=False in docker.compose.run(...)."
             )
         full_cmd = self.docker_compose_cmd + ["run"]
+        full_cmd.add_flag("--build", build)
         full_cmd.add_flag("--detach", detach)
         full_cmd.add_simple_arg("--name", name)
         full_cmd.add_flag("--no-TTY", not tty)


Test patch:
diff --git a/tests/python_on_whales/components/test_compose.py b/tests/python_on_whales/components/test_compose.py
index e7fc7d5a..aa8200da 100644
--- a/tests/python_on_whales/components/test_compose.py
+++ b/tests/python_on_whales/components/test_compose.py
@@ -860,3 +860,14 @@ def test_docker_compose_up_remove_orphans():
     docker.compose.down(timeout=1)
     check_number_of_running_containers(docker, 0, compose_container_ids)
     remove(compose_file)
+
+
+def test_docker_compose_run_build():
+    docker.compose.run("my_service", build=True, detach=True, tty=False)
+    docker.compose.stop()
+    docker.compose.rm()
+    assert (
+        docker.compose.config(return_json=True)["services"]["my_service"]["image"]
+        == docker.image.list("some_random_image")[0].repo_tags[0].split(":latest")[0]
+    )
+    docker.image.remove("some_random_image", force=True)