Skip to content

Commit 5c7f980

Browse files
check_newsfragments: Improve output on Windows machines (#7612)
Co-authored-by: Pierre Sassoulas <[email protected]>
1 parent dfd0e5a commit 5c7f980

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

script/check_newsfragments.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ def check_file(file: Path, verbose: bool) -> bool:
5151
if match:
5252
issue = match.group("issue")
5353
if file.stem != issue:
54-
print(
54+
echo(
5555
f"{file} must be named '{issue}.<fragmenttype>', after the issue it references."
5656
)
5757
return False
5858
if verbose:
59-
print(f"Checked '{file}': LGTM 🤖👍")
59+
echo(f"Checked '{file}': LGTM 🤖👍")
6060
return True
61-
print(
61+
echo(
6262
f"""\
6363
{file}: does not respect the standard format 🤖👎
6464
@@ -82,5 +82,11 @@ def check_file(file: Path, verbose: bool) -> bool:
8282
return False
8383

8484

85+
def echo(msg: str) -> None:
86+
# To support non-UTF-8 environments like Windows, we need
87+
# to explicitly encode the message instead of using plain print()
88+
sys.stdout.buffer.write(f"{msg}\n".encode())
89+
90+
8591
if __name__ == "__main__":
8692
sys.exit(main())

0 commit comments

Comments
 (0)