Skip to content

Commit b2efa5e

Browse files
uranusjrephraimbuddy
authored andcommitted
Clean up Breeze output for Docker context (#38857)
(cherry picked from commit 5d10c4a)
1 parent bfa6811 commit b2efa5e

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

dev/breeze/src/airflow_breeze/utils/docker_command_utils.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ def autodetect_docker_context():
648648
# On Windows, some contexts are used for WSL2. We don't want to use those.
649649
if context["DockerEndpoint"] == "npipe:////./pipe/dockerDesktopLinuxEngine":
650650
continue
651-
get_console().print(f"[info]Using {preferred_context_name} as context.[/]")
651+
get_console().print(f"[info]Using {preferred_context_name!r} as context.[/]")
652652
return preferred_context_name
653653
fallback_context = next(iter(known_contexts))
654654
get_console().print(
@@ -662,11 +662,9 @@ def get_and_use_docker_context(context: str):
662662
if context == "autodetect":
663663
context = autodetect_docker_context()
664664
run_command(["docker", "context", "create", context], check=False)
665-
output = run_command(["docker", "context", "use", context], check=False)
666-
if output.returncode != 0:
667-
get_console().print(
668-
f"[warning] Could no use the context {context}. Continuing with current context[/]"
669-
)
665+
output = run_command(["docker", "context", "use", context], check=False, stdout=DEVNULL, stderr=DEVNULL)
666+
if output.returncode:
667+
get_console().print(f"[warning]Could no use context {context!r}. Continuing with current context[/]")
670668
return context
671669

672670

dev/breeze/tests/test_docker_command_utils.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def _fake_ctx_output(*names: str) -> str:
205205
(
206206
_fake_ctx_output("default"),
207207
"default",
208-
"[info]Using default as context",
208+
"[info]Using 'default' as context",
209209
),
210210
("\n", "default", "[warning]Could not detect docker builder"),
211211
(
@@ -216,22 +216,22 @@ def _fake_ctx_output(*names: str) -> str:
216216
(
217217
_fake_ctx_output("a", "desktop-linux"),
218218
"desktop-linux",
219-
"[info]Using desktop-linux as context",
219+
"[info]Using 'desktop-linux' as context",
220220
),
221221
(
222222
_fake_ctx_output("a", "default"),
223223
"default",
224-
"[info]Using default as context",
224+
"[info]Using 'default' as context",
225225
),
226226
(
227227
_fake_ctx_output("a", "default", "desktop-linux"),
228228
"desktop-linux",
229-
"[info]Using desktop-linux as context",
229+
"[info]Using 'desktop-linux' as context",
230230
),
231231
(
232232
'[{"Name": "desktop-linux", "DockerEndpoint": "unix://desktop-linux"}]',
233233
"desktop-linux",
234-
"[info]Using desktop-linux as context",
234+
"[info]Using 'desktop-linux' as context",
235235
),
236236
],
237237
)

0 commit comments

Comments
 (0)