Skip to content

Commit aa5e69f

Browse files
committed
Set encoding in Python scripts.
1 parent 00b287c commit aa5e69f

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

build_libtcod.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def __init__(self, path: str) -> None:
5858
self.path = path = os.path.normpath(path)
5959
directory = os.path.dirname(path)
6060
depends = set()
61-
with open(self.path, "r") as f:
61+
with open(self.path, "r", encoding="utf-8") as f:
6262
header = f.read()
6363
header = RE_COMMENT.sub("", header)
6464
header = RE_CPLUSPLUS.sub("", header)
@@ -251,7 +251,7 @@ def fix_header(filepath: str) -> None:
251251
252252
This whitespace is causing issues with directives on some platforms.
253253
"""
254-
with open(filepath, "r+") as f:
254+
with open(filepath, "r+", encoding="utf-8") as f:
255255
current = f.read()
256256
fixed = "\n".join(line.strip() for line in current.split("\n"))
257257
if current == fixed:
@@ -406,11 +406,11 @@ def update_module_all(filename: str, new_all: str) -> None:
406406
r"(.*# --- From constants.py ---).*(# --- End constants.py ---.*)",
407407
re.DOTALL,
408408
)
409-
with open(filename, "r") as f:
409+
with open(filename, "r", encoding="utf-8") as f:
410410
match = RE_CONSTANTS_ALL.match(f.read())
411411
assert match, "Can't determine __all__ subsection in %s!" % (filename,)
412412
header, footer = match.groups()
413-
with open(filename, "w") as f:
413+
with open(filename, "w", encoding="utf-8") as f:
414414
f.write("%s\n %s,\n %s" % (header, new_all, footer))
415415

416416

@@ -431,7 +431,7 @@ def write_library_constants() -> None:
431431
import tcod.color
432432
from tcod._libtcod import ffi, lib
433433

434-
with open("tcod/constants.py", "w") as f:
434+
with open("tcod/constants.py", "w", encoding="utf-8") as f:
435435
all_names = []
436436
f.write(CONSTANT_MODULE_HEADER)
437437
for name in dir(lib):
@@ -473,7 +473,7 @@ def write_library_constants() -> None:
473473
update_module_all("tcod/__init__.py", all_names_merged)
474474
update_module_all("tcod/libtcodpy.py", all_names_merged)
475475

476-
with open("tcod/event_constants.py", "w") as f:
476+
with open("tcod/event_constants.py", "w", encoding="utf-8") as f:
477477
all_names = []
478478
f.write(EVENT_CONSTANT_MODULE_HEADER)
479479
f.write("# --- SDL scancodes ---\n")
@@ -490,7 +490,7 @@ def write_library_constants() -> None:
490490
all_names_merged = ",\n ".join('"%s"' % name for name in all_names)
491491
f.write("\n__all__ = [\n %s,\n]\n" % (all_names_merged,))
492492

493-
with open("tcod/event.py", "r") as f:
493+
with open("tcod/event.py", "r", encoding="utf-8") as f:
494494
event_py = f.read()
495495

496496
event_py = re.sub(
@@ -506,7 +506,7 @@ def write_library_constants() -> None:
506506
flags=re.DOTALL,
507507
)
508508

509-
with open("tcod/event.py", "w") as f:
509+
with open("tcod/event.py", "w", encoding="utf-8") as f:
510510
f.write(event_py)
511511

512512

parse_sdl2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
def get_header(name: str) -> str:
2929
"""Return the source of a header in a partially preprocessed state."""
30-
with open(name, "r") as f:
30+
with open(name, "r", encoding="utf-8") as f:
3131
header = f.read()
3232
# Remove Doxygen code.
3333
header = RE_REMOVALS.sub("", header)

scripts/get_release_description.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
def main() -> None:
1212
# Get the most recent tag.
13-
with open("CHANGELOG.rst", "r") as f:
13+
with open("CHANGELOG.rst", "r", encoding="utf-8") as f:
1414
match = RE_BODY.match(f.read())
1515
assert match
1616
body = match.groups()[0].strip()

scripts/tag_release.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
def parse_changelog(args: Any) -> Tuple[str, str]:
2121
"""Return an updated changelog and and the list of changes."""
22-
with open("CHANGELOG.rst", "r") as file:
22+
with open("CHANGELOG.rst", "r", encoding="utf-8") as file:
2323
match = re.match(
2424
pattern=r"(.*?Unreleased\n---+\n)(.+?)(\n*[^\n]+\n---+\n.*)",
2525
string=file.read(),
@@ -48,7 +48,7 @@ def main() -> None:
4848
new_changelog, changes = parse_changelog(args)
4949

5050
if not args.dry_run:
51-
with open("CHANGELOG.rst", "w") as f:
51+
with open("CHANGELOG.rst", "w", encoding="utf-8") as f:
5252
f.write(new_changelog)
5353
edit = ["-e"] if args.edit else []
5454
subprocess.check_call(["git", "commit", "-avm", "Prepare %s release." % args.tag] + edit)

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ def get_version() -> str:
3030
version += ".dev%i" % commits_since_tag
3131

3232
# update tcod/version.py
33-
with open(PATH / "tcod/version.py", "w") as version_file:
33+
with open(PATH / "tcod/version.py", "w", encoding="utf-8") as version_file:
3434
version_file.write(f'__version__ = "{version}"\n')
3535
return version
3636
else: # Not a Git respotitory.
3737
try:
38-
with open(PATH / "tcod/version.py") as version_file:
38+
with open(PATH / "tcod/version.py", encoding="utf-8") as version_file:
3939
match = re.match(r'__version__ = "(\S+)"', version_file.read())
4040
assert match
4141
return match.groups()[0]
@@ -68,7 +68,7 @@ def get_package_data() -> List[str]:
6868

6969
def get_long_description() -> str:
7070
"""Return this projects description."""
71-
with open(PATH / "README.rst", "r") as readme_file:
71+
with open(PATH / "README.rst", "r", encoding="utf-8") as readme_file:
7272
return readme_file.read()
7373

7474

0 commit comments

Comments
 (0)