-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Instruct Azure CLI to not color output #11362
Conversation
Hi @NVolcz, thanks for opening this! I was able to reproduce the problem locally with an older version of the CLI but not with the latest version (2.5.1). Do you still see this problem with the latest CLI? |
Upgrading to Azure CLI to 2.5.1 fixed this, thanks! I was running version 2.3.1 of the CLI. |
Great, then it seems that while adding |
It seems that this behavior has once again changed. I am now running azure-cli 2.7.0 and are getting the color reset sequence in the end of the JSON. |
That's interesting, I don't see it from 2.7.0 either. @jiasli, what default coloring behavior should we expect from |
I am able to repro. The testing script is very simple: from azure.identity import AzureCliCredential
cred = AzureCliCredential()
token = cred.get_token('https://management.azure.com/')
print(token) Add a breakpoint at: azure-sdk-for-python/sdk/identity/azure-identity/azure/identity/_credentials/azure_cli.py Line 57 in a7ac22a
In a shell, the issue doesn't occur:
This issue should always be there. We didn't change anything when color does get enabled. When if 'PYCHARM_HOSTED' in os.environ:
if stream is not None and (stream is sys.__stdout__ or stream is sys.__stderr__):
return True So, colorama will print the control sequence def reset_all(self):
if self.convert:
self.call_win32('m', (0,))
elif not self.strip and not self.stream.closed:
self.wrapped.write(Style.RESET_ALL) I think this is more of an issue with colorama and PyCharm. For Azure CLI and Azure Identity, the best approach is to explicitly disable color in Azure CLI so that colorama never gets initiated. I have created issue tartley/colorama#263 in colorama's repo. |
Would it be crazy to suggest to reconsider my pull request in light of this impediment with colorama? |
Not at all, that would be entirely reasonable because it seems we must do something here 😄 If you want to fix up this pull request, my feedback on its current state is:
If not, no worries, we'll get this fixed in the next release. |
68216eb
to
ad86112
Compare
I have updated my PR but haven't verified that it works on Linux yet. |
Thanks for the update. There are still a couple things left to get this over the finish line: I'd rather set the environment variable with the This needs to merge early next week to make the next release. Is that too soon for you? I can push a couple commits to finish this if you like. |
4e8c2d4
to
d225585
Compare
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
How about now? |
Looks good to me, I'll take it 😄 Thanks for reporting this, and for fixing it! |
…into regenerate_certs * 'master' of https://github.com/Azure/azure-sdk-for-python: (27 commits) Set http_logging_policy in Configuration (Azure#12218) Sync eng/common directory with azure-sdk-tools repository (Azure#11990) AzureCliCredential instructs CLI not to color output (Azure#11362) Sdk automation/track2 azure mgmt storage (Azure#12238) Fix changelog of CustomVision (Azure#12225) Doc update for conf file name (Azure#12224) update doc for content_type (Azure#12220) update API version to use 2020-06-30 (Azure#12208) Use MSAL's custom transport API (Azure#11892) add breadcumbs for training filter (Azure#12196) [formrecognizer] arch board feedback renames (Azure#12207) Dataplane autogeneration (Azure#12210) update version number and API_version support (Azure#12154) Update SECURITY.md (Azure#12209) adding a pip freeze to ensure we fully understand what our environment has (Azure#12173) FaceAPI 0.4.1 (Azure#12199) [ServiceBus] Enable Async Unittest (Azure#12001) add search owver (Azure#12190) update training docstring (Azure#12168) don't use mgmt track2 (Azure#12183) ...
…into regenerate_keys * 'master' of https://github.com/Azure/azure-sdk-for-python: Set http_logging_policy in Configuration (Azure#12218) Sync eng/common directory with azure-sdk-tools repository (Azure#11990) AzureCliCredential instructs CLI not to color output (Azure#11362) Sdk automation/track2 azure mgmt storage (Azure#12238) Fix changelog of CustomVision (Azure#12225) Doc update for conf file name (Azure#12224) update doc for content_type (Azure#12220) update API version to use 2020-06-30 (Azure#12208) Use MSAL's custom transport API (Azure#11892) add breadcumbs for training filter (Azure#12196) [formrecognizer] arch board feedback renames (Azure#12207) Dataplane autogeneration (Azure#12210) update version number and API_version support (Azure#12154) Update SECURITY.md (Azure#12209) adding a pip freeze to ensure we fully understand what our environment has (Azure#12173) FaceAPI 0.4.1 (Azure#12199) [ServiceBus] Enable Async Unittest (Azure#12001) add search owver (Azure#12190) update training docstring (Azure#12168)
…into regenerate_secrets * 'master' of https://github.com/Azure/azure-sdk-for-python: (36 commits) Install dev dependency when running apistub (Azure#12268) SharedTokenCacheCredential lazily loads the cache (Azure#12172) Changes in docs [Form Recognizer] (Azure#12216) [formrecognizer] adjust text angle to fit in specified interval (Azure#12248) Set http_logging_policy in Configuration (Azure#12218) Sync eng/common directory with azure-sdk-tools repository (Azure#11990) AzureCliCredential instructs CLI not to color output (Azure#11362) Sdk automation/track2 azure mgmt storage (Azure#12238) Fix changelog of CustomVision (Azure#12225) Doc update for conf file name (Azure#12224) update doc for content_type (Azure#12220) update API version to use 2020-06-30 (Azure#12208) Use MSAL's custom transport API (Azure#11892) add breadcumbs for training filter (Azure#12196) [formrecognizer] arch board feedback renames (Azure#12207) Dataplane autogeneration (Azure#12210) update version number and API_version support (Azure#12154) Update SECURITY.md (Azure#12209) adding a pip freeze to ensure we fully understand what our environment has (Azure#12173) FaceAPI 0.4.1 (Azure#12199) ...
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: https://github.com/Azure/azure-cli/issues/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