Skip to content

Commit ffefbbb

Browse files
authored
AzureCliCredential instructs CLI not to color output (#11362)
1 parent fff6eb3 commit ffefbbb

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

sdk/identity/azure-identity/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Release History
22

33
## 1.4.0b6 (Unreleased)
4+
- `AzureCliCredential` no longer raises an exception due to unexpected output
5+
from the CLI when run by PyCharm (thanks @NVolcz)
6+
([#11362](https://github.com/Azure/azure-sdk-for-python/pull/11362))
47
- Upgraded minimum `msal` version to 1.3.0
58
- The async `AzureCliCredential` correctly invokes `/bin/sh`
69
([#12048](https://github.com/Azure/azure-sdk-for-python/issues/12048))

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

+6-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,11 @@ 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,
73+
stdout=asyncio.subprocess.PIPE,
74+
stderr=asyncio.subprocess.STDOUT,
75+
cwd=working_directory,
76+
env=dict(os.environ, AZURE_CORE_NO_COLOR="true")
7277
)
7378
except OSError as ex:
7479
# failed to execute 'cmd' or '/bin/sh'; CLI may or may not be installed

0 commit comments

Comments
 (0)