Repository navigation
[Core] az: Add core.output_newline and default to LF line endings when run from WSL or Git Bash on Windows - #34236
Phil Sphicas (philsphicas) wants to merge 1 commit into
Conversation
… bash on Windows On Windows, Python's text-mode stdout translates every "\n" to "\r\n", so `FOO=$(az ... -o tsv)` from WSL or Git Bash captures a trailing "\r", and "\r\n" already present in data is written as "\r\r\n". - New config `core.output_newline` (`native` | `lf`, env AZURE_CORE_OUTPUT_NEWLINE). `lf` reconfigures stdout in place with newline="\n"; `native` keeps today's behavior. - The MSI bash launcher (wbin/az, used by WSL and Git Bash) sets AZ_LAUNCHER=bash, which defaults the setting to `lf`. Explicit env/config always wins. - The launcher adds AZ_LAUNCHER to WSLENV so it reaches the Windows process under WSL. - cmd/PowerShell behavior is unchanged unless the setting is configured. Fixes Azure#33385 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e8fa45af-9457-40bb-b8c7-3b159937f2e4
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
Thank you for your contribution Phil Sphicas (@philsphicas)! We will review the pull request and get back to you soon. |
There was a problem hiding this comment.
🟢 Approval recommended
The changes are localized, preserve native defaults for other launchers, and have focused regression coverage with no unresolved findings.
0 open findings
What changed in this PR
Adds configurable stdout line endings to prevent stray carriage returns when Windows Azure CLI output is consumed by WSL or Git Bash.
Changes:
- Adds
core.output_newlinewith environment/config overrides and a launcher-dependent default. - Enables LF by default through the Windows bash launcher while preserving native behavior elsewhere.
- Adds regression tests for configuration precedence, byte output, and fallback behavior.
| File | Description |
|---|---|
| src/azure-cli/azure/cli/__main__.py | Registers newline handling before command execution. |
| src/azure-cli-core/azure/cli/core/tests/test_output.py | Tests newline selection and stream behavior. |
| src/azure-cli-core/azure/cli/core/_output.py | Resolves configuration and reconfigures stdout. |
| src/azure-cli-core/azure/cli/core/_environment.py | Defines the launcher environment-variable constant. |
| build_scripts/windows/scripts/az | Marks bash invocation and forwards the marker through WSL. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
X Engineering Agent ReportReview — Comments Agent review: no confirmed findingsTraced launcher defaults, config precedence and pre-execution stdout reconfiguration; byte assertions distinguish LF preservation from native CRLF translation. No actionable defect confirmed. Windows/WSL/Git Bash execution was not independently verified; upstream CI reports 55/55 passed. The detector section below is low-confidence: its zero-production-files classification does not capture these runtime changes. Test validation
Risk assessment — 0/100 · LowThe Low rating reflects the detected change scope with no elevated security, reliability, customer, operational, dependency, sovereign-cloud, generated-output, or cross-component signal.
Posted by x-engineering-agent (Reviewer) |
There was a problem hiding this comment.
Phil Sphicas (@philsphicas) Ready for human review. See the X Engineering Agent Report.
🤖 PR Validation — ️✔️ All clear
Related command
az(all commands): stdout line endings of the Windows MSI install when invoked from bash (WSL, Git Bash)Description
Fixes #33385.
On Windows, Python's text-mode
sys.stdoutconverts every\nto\r\nwhen writing. When the Windowsazis called from WSL or Git Bash,FOO=$(az ... -o tsv)therefore captures a trailing\r, andfor x in $(az ... -o tsv)gives every item except the last a stray\r. That\rends up in laterazcalls and causes misleading errors such as400 Bad Request. Data that already contains\r\nis also corrupted to\r\r\n.The cause is the stdout stream, not the tsv formatter, so this affects every
-oformat and commands thatprint()directly (e.g.az aks get-credentials --file -,--help,--version).Changes:
core.output_newline(native|lf; env varAZURE_CORE_OUTPUT_NEWLINEvia the usual knack mapping).lfcallsstdout.reconfigure(newline='\n')in place, so text is written exactly as generated, with no conversion and no\r\r\ncorruption.nativekeeps today's behaviour.build_scripts/windows/scripts/az→CLI2\wbin\az, which WSL and Git Bash run foraz) setsAZ_LAUNCHER=bashand adds it toWSLENV, so LF becomes the default for bash callers only. An explicit env var or config value always wins.azure/cli/__main__.pyvia anEVENT_CLI_PRE_EXECUTEhandler: logging is configured by then and no command output has been written yet. Library use ofget_default_cli().invoke()orrun_az_cmd()is unaffected.Effect:
azon Linux and macOS.az storage blob downloadto stdout), and child processes.Related: #33427 takes a tsv-only approach to the same issue. This change also covers json, yaml, table and direct
print()output, preserves CRLF already in data, and leaves non-bash Windows callers unchanged.Testing Guide
Unit tests (10 new in
src/azure-cli-core/azure/cli/core/tests/test_output.py) cover:reconfigureCommands run and results:
python -m unittest azure.cli.core.tests.test_output azure.cli.core.tests.test_util: passed (48 tests). This was run with the Python bundled in the Windows MSI install (2.90.0), with this branch'ssrc/azure-cli-coreandsrc/azure-cliplaced first onsys.path.azdev testwas not run: dependency installation failed locally with a TLS error.flake8 --max-line-length 120on the changed Python files: passed.pylint --rcfile=pylintrc src/azure-cli-core/azure/cli/core/_output.py: passed except R0903 onAzOutputProducer, which is reported for the unmodified file too.shellcheck build_scripts/windows/scripts/az: passed.--help,--versionand bareazAZURE_CORE_OUTPUT_NEWLINE=native(added toWSLENV) → CRLFWARNING:, hidden by--only-show-errorsWSLENVentries (includingAZ_LAUNCHER/u)Manual check from WSL or Git Bash with an MSI install that includes this change:
From PowerShell or cmd, output is unchanged (CRLF) unless
core.output_newline=lfis set.History Notes
[Core]
az: Addcore.output_newlineconfig (native|lf) and default to LF line endings on stdout when run from WSL or Git Bash on WindowsThis checklist is used to make sure that common guidelines for a pull request are followed.
The PR title and description has followed the guideline in Submitting Pull Requests.
I adhere to the Command Guidelines.
I adhere to the Error Handling Guidelines.