Repository navigation
fix(cmd-version): read & write toml and pattern version files as UTF-8 - #1518
Open
stella-h-choi wants to merge 2 commits into
Open
stella-h-choi wants to merge 2 commits into
stella-h-choi wants to merge 2 commits into
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
They were read and written in the locale's encoding, so stamping a file with non-ASCII text failed on a Windows with a legacy code page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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
semantic-release versionfails where the locale's encoding is not UTF-8 (Windows with cp1252 or cp949) andpyproject.tomlor a stamped source file holds non-ASCII text, such as an author's name: the files are read and written withPath.read_text()/write_text()without an encoding.Rationale
TOML is UTF-8 by its specification, and Python source is UTF-8 by default, so these files are now read and written as UTF-8:
TomlVersionDeclarationandPatternVersionDeclaration, when a version is stampedpyproject.tomlread for the project metadata inRuntimeContext.from_raw_configFileVersionDeclaration(the file is only the version) and the deprecatedVersionDeclarationABCare left as they are. #1505 does the same for the changelog and does not touch these files.A file matched by
version_variablesthat is saved in a legacy code page with non-ASCII text was stamped on a Windows of that code page before and is refused as not UTF-8 now. It was already refused where the locale is UTF-8.How did you test?
A unit test for each of the two declarations stamps a file with non-ASCII text and compares it byte-decoded with the original. Linux, Python 3.14,
tests/unit/semantic_release/versionandtests/unit/semantic_release/cli/test_config.py(474 tests):masterwith the new testsThe one that fails everywhere here,
test_toml_declaration_from_definition[Default number format for project.version], is about the quote style and fails onmasterwithout this change.All unit tests (
pytest -m unit, C.UTF-8): 4309 tests with 1 failure onmaster, 4311 with the same 1 failure on this branch.The command itself, in a new repository whose
pyproject.tomlandm.pyhold Korean text (version --no-commit --no-tag --no-push --no-vcs-release --no-changelog --skip-build):masterOn a UTF-8 host the new unit tests pass without the fix as well; they guard it on a host with another locale, such as Windows. The suite was not run on Windows, and the end-to-end tests were not run.
How to Verify
LC_ALL=ko_KR.EUC-KR PYTHONUTF8=0 pytest tests/unit/semantic_release/version/declarations -k utf8: both fail withUnicodeDecodeError.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)
Appropriate Unit tests added/updated
Appropriate End-to-End tests added/updated
Appropriate Documentation added/updated and syntax validated for sphinx build (see Contributor Guidelines)
🤖 Generated with Claude Code