Skip to content

Commit 8455133

Browse files
committed
Instruct Azure CLI to not color output
The Azure CLI supports colored output by using colorama which resets the color after execution by printing "[0m" if the terminal supports color. This can in some cases cause the AzureCliCredential to fail for example when developing in PyCharm: Azure/azure-cli#9903 Azure CLI allows color output to be disabled by setting the environment variable:AZURE_CORE_NO_COLOR. The PR in azure-cli: Azure/azure-cli#12601
1 parent c01658b commit 8455133

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

sdk/identity/azure-identity/azure/identity/_credentials/azure_cli.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,12 @@ def _run_command(command):
104104
try:
105105
working_directory = get_safe_working_dir()
106106

107-
kwargs = {"stderr": subprocess.STDOUT, "cwd": working_directory, "universal_newlines": True}
107+
kwargs = {
108+
"stderr": subprocess.STDOUT,
109+
"cwd": working_directory,
110+
"universal_newlines": True,
111+
"env": dict(os.environ, AZURE_CORE_NO_COLOR="true")
112+
}
108113
if platform.python_version() >= "3.3":
109114
kwargs["timeout"] = 10
110115

sdk/identity/azure-identity/azure/identity/aio/_credentials/azure_cli.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# ------------------------------------
55
import asyncio
66
import sys
7+
import os
78

89
from azure.core.exceptions import ClientAuthenticationError
910
from .._credentials.base import AsyncCredentialBase
@@ -68,7 +69,10 @@ async def _run_command(command):
6869

6970
try:
7071
proc = await asyncio.create_subprocess_exec(
71-
*args, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.STDOUT, cwd=working_directory
72+
*args, stdout=asyncio.subprocess.PIPE,
73+
stderr=asyncio.subprocess.STDOUT,
74+
cwd=working_directory,
75+
env=dict(os.environ, AZURE_CORE_NO_COLOR="true")
7276
)
7377
except OSError as ex:
7478
# failed to execute 'cmd' or '/bin/sh'; CLI may or may not be installed

0 commit comments

Comments
 (0)