fix(cmd-generate-config): fix output encoding to work on windows#1400
Merged
codejedi365 merged 3 commits intopython-semantic-release:masterfrom Jan 5, 2026
Merged
Conversation
8262589 to
13d3c31
Compare
…config` usage example
13d3c31 to
de354d7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
Fixes #702 -
generate-configcommand produces files with NUL characters on Windows, making configuration files unreadable by TOML/JSON parsers.On Windows PowerShell, the
generate-configcommand outputs UTF-16LE encoded data when redirected with>>or>, inserting NUL bytes between every character. This makes the generated configuration files unusable.Rationale
Root Cause Analysis:
>,>>) default to UTF-16LE encoding on Windowsclick.echo()writes text to stdout, which PowerShell then re-encodesSolution:
generate_config()to write directly tosys.stdout.bufferas UTF-8 bytesclick.echo()for compatibility with non-standard environmentsWhy this approach:
Out-FilecmdletOut-File -Encoding utf8continue to workAlternatives considered:
sys.stdout.reconfigure(encoding='utf-8')- PowerShell's>>still overrides itPYTHONIOENCODING=utf-8- Requires user action before running commandHow did you test?
Reproduction of Original Issue:
semantic-release generate-config -f toml --pyproject >> config.tomlon Windows PowerShell 5.xFormat-Hex)Validation of Fix:
sys.stdout.buffer)$PSDefaultParameterValues['Out-File:Encoding'] = 'utf8'Test Coverage:
generate-configtests pass unchangedtest_generate_config_emits_utf8_bytes_windows():test_generate_config_stdout_decodes_utf8():Edge Cases Tested:
--pyprojectflagHow to Verify
On Windows PowerShell:
Checkout this branch and install the package:
pip install -e .Test with PowerShell default encoding (should now work with proper PowerShell settings):
Verify the file is UTF-8 encoded:
Test with recommended
Out-Fileapproach:Verify the config is parseable:
Run the test suite:
pytest tests/e2e/cmd_config/test_generate_config.py -v # All 8 tests should pass (6 existing + 2 new)Check documentation rendering:
PR Completion Checklist
Reviewed & followed the Contributor Guidelines
Changes Implemented & Validation pipeline succeeds
Commits follow the Conventional Commits standard
and are separated into the proper commit type and scope (recommended order: test, build, feat/fix, docs)
docs(planning): add action plan for issue #704test(cmd-config): add UTF-8 encoding tests for generate-config+ docs updatesAppropriate Unit tests added/updated
Appropriate End-to-End tests added/updated
test_generate_config_emits_utf8_bytes_windows()- Windows-specific subprocess testtest_generate_config_stdout_decodes_utf8()- Cross-platform UTF-8 validationAppropriate Documentation added/updated and syntax validated for sphinx build (see Contributor Guidelines)
docs/api/commands.rstwith Windows PowerShell UTF-8 redirection guidancedocs/misc/troubleshooting.rstsection for Windows NUL character issue