Skip to content

Commit

Permalink
Instruct Azure CLI to not color output
Browse files Browse the repository at this point in the history
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
  • Loading branch information
NVolcz committed Jun 27, 2020
1 parent c01658b commit 8455133
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ def _run_command(command):
try:
working_directory = get_safe_working_dir()

kwargs = {"stderr": subprocess.STDOUT, "cwd": working_directory, "universal_newlines": True}
kwargs = {
"stderr": subprocess.STDOUT,
"cwd": working_directory,
"universal_newlines": True,
"env": dict(os.environ, AZURE_CORE_NO_COLOR="true")
}
if platform.python_version() >= "3.3":
kwargs["timeout"] = 10

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# ------------------------------------
import asyncio
import sys
import os

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

try:
proc = await asyncio.create_subprocess_exec(
*args, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.STDOUT, cwd=working_directory
*args, stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.STDOUT,
cwd=working_directory,
env=dict(os.environ, AZURE_CORE_NO_COLOR="true")
)
except OSError as ex:
# failed to execute 'cmd' or '/bin/sh'; CLI may or may not be installed
Expand Down

0 comments on commit 8455133

Please sign in to comment.