Skip to content

Commit 982377c

Browse files
authored
fix: Use UTF-8 encoding in all text-mode open() calls
This was causing issues on the annoying operating system. PR-105: #105
1 parent 9f84e54 commit 982377c

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/git_changelog/_internal/cli.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ def render(
676676
# Render new entries in-place.
677677
if in_place:
678678
# Read current changelog lines.
679-
with open(output) as changelog_file: # type: ignore[arg-type]
679+
with open(output, encoding="utf8") as changelog_file: # type: ignore[arg-type]
680680
lines = changelog_file.read().splitlines()
681681

682682
# Prepare version regex and marker line.
@@ -720,7 +720,7 @@ def render(
720720
lines[marker : marker + marker2 + 2] = [rendered]
721721

722722
# Write back updated changelog lines.
723-
with open(output, "w") as changelog_file: # type: ignore[arg-type]
723+
with open(output, "w", encoding="utf8") as changelog_file: # type: ignore[arg-type]
724724
changelog_file.write("\n".join(lines).rstrip("\n") + "\n")
725725

726726
# Overwrite output file.
@@ -731,7 +731,7 @@ def render(
731731
if output is sys.stdout:
732732
sys.stdout.write(rendered)
733733
else:
734-
with open(output, "w") as stream: # type: ignore[arg-type]
734+
with open(output, "w", encoding="utf8") as stream: # type: ignore[arg-type]
735735
stream.write(rendered)
736736

737737
return rendered
@@ -840,7 +840,7 @@ def get_release_notes(
840840
release_notes = []
841841
found_marker = False
842842
found_version = False
843-
with open(input_file) as changelog:
843+
with open(input_file, encoding="utf8") as changelog:
844844
for line in changelog:
845845
line = line.strip() # noqa: PLW2901
846846
if not found_marker:

tests/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def commit(self, message: str) -> str:
5959
Returns:
6060
The Git commit hash.
6161
"""
62-
with self.path.joinpath(str(uuid.uuid4())).open("w") as fh:
62+
with self.path.joinpath(str(uuid.uuid4())).open("w", encoding="utf8") as fh:
6363
fh.write(str(random.randint(0, 1))) # noqa: S311
6464
self.git("add", "-A")
6565
self.git("commit", "-m", message)

0 commit comments

Comments
 (0)