From 9fc30f09203eb30f86ee0bfc431e838021156772 Mon Sep 17 00:00:00 2001 From: Bernard Cooke Date: Sun, 28 May 2023 12:26:19 +0100 Subject: [PATCH] fix: open all files with explicit utf-8 encoding --- semantic_release/history/__init__.py | 6 +++--- semantic_release/settings.py | 4 ++-- semantic_release/vcs_helpers.py | 4 ++-- tests/test_cli.py | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/semantic_release/history/__init__.py b/semantic_release/history/__init__.py index cb557b6d0..d85eb49a5 100644 --- a/semantic_release/history/__init__.py +++ b/semantic_release/history/__init__.py @@ -115,7 +115,7 @@ def __init__(self, path, key): self.key = key def _read(self) -> Dotty: - toml_doc = tomlkit.loads(self.path.read_text()) + toml_doc = tomlkit.loads(self.path.read_text(encoding="utf-8")) return Dotty(toml_doc) def parse(self) -> Set[str]: @@ -157,7 +157,7 @@ def parse(self) -> Set[str]: should be the same version in each place), but it falls on the caller to check for this condition. """ - content = self.path.read_text() + content = self.path.read_text(encoding="utf-8") versions = { m.group(1) for m in re.finditer(self.pattern, content, re.MULTILINE) @@ -178,7 +178,7 @@ def replace(self, new_version: str): :param new_version: The new version number as a string """ n = 0 - old_content = self.path.read_text() + old_content = self.path.read_text(encoding="utf-8") def swap_version(m): nonlocal n diff --git a/semantic_release/settings.py b/semantic_release/settings.py index cfa66cd31..f787b490a 100644 --- a/semantic_release/settings.py +++ b/semantic_release/settings.py @@ -34,7 +34,7 @@ def _config(): def _config_from_ini(paths): parser = configparser.ConfigParser() - parser.read(paths) + parser.read(paths, encoding="utf-8") flags = { "changelog_capitalize", @@ -69,7 +69,7 @@ def _config_from_ini(paths): def _config_from_pyproject(path): if os.path.isfile(path): try: - with open(path, "r") as f: + with open(path, "r", encoding="utf-8") as f: pyproject = tomlkit.loads(f.read()) if pyproject: return pyproject.get("tool", {}).get("semantic_release", {}) diff --git a/semantic_release/vcs_helpers.py b/semantic_release/vcs_helpers.py index ed80d90f5..641f33f75 100644 --- a/semantic_release/vcs_helpers.py +++ b/semantic_release/vcs_helpers.py @@ -182,11 +182,11 @@ def update_changelog_file(version: str, content_to_add: str): changelog_file = config.get("changelog_file") changelog_placeholder = config.get("changelog_placeholder") git_path = Path(os.getcwd(), changelog_file) - if not git_path.exists() or git_path.read_text().strip() == "": + if not git_path.exists() or git_path.read_text(encoding="utf-8").strip() == "": original_content = f"# Changelog\n\n{changelog_placeholder}\n" logger.warning(f"Changelog file not found: {git_path} - creating it.") else: - original_content = git_path.read_text() + original_content = git_path.read_text(encoding="utf-8") if ( changelog_placeholder not in original_content and "# Changelog" in original_content diff --git a/tests/test_cli.py b/tests/test_cli.py index a556376bf..1cac19595 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1230,7 +1230,7 @@ def test_overload_by_cli(mocker, runner): ], ) - mock_read_text.assert_called_once_with() + mock_read_text.assert_called_once_with(encoding="utf-8") mock_read_text.reset_mock()