Skip to content

Commit 52597a5

Browse files
authored
Fix Python scripts for Windows: UTF-8 encoding (#485)
To avoid problems with various symbols, we have to specify the encoding when we read files. The actual codec name is `utf_8` but aliases like `utf8`, `utf-8`, etc are accepted. Here, I'm using `utf-8` alias. https://docs.python.org/3.8/library/codecs.html#standard-encodings This fixes `make lesson-check` when running under 'Git for Windows' for lessons that have non-cp1252 characters.
1 parent 95221b1 commit 52597a5

3 files changed

Lines changed: 4 additions & 4 deletions

File tree

bin/lesson_check.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def read_references(reporter, ref_path):
215215
result = {}
216216
urls_seen = set()
217217

218-
with open(ref_path, 'r') as reader:
218+
with open(ref_path, 'r', encoding='utf-8') as reader:
219219
for (num, line) in enumerate(reader, 1):
220220

221221
if P_INTERNAL_INCLUDE_LINK.search(line): continue

bin/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def read_markdown(parser, path):
105105
"""
106106

107107
# Split and extract YAML (if present).
108-
with open(path, 'r') as reader:
108+
with open(path, 'r', encoding='utf-8') as reader:
109109
body = reader.read()
110110
metadata_raw, metadata_yaml, body = split_metadata(path, body)
111111

@@ -160,7 +160,7 @@ def load_yaml(filename):
160160
"""
161161

162162
try:
163-
with open(filename, 'r') as reader:
163+
with open(filename, 'r', encoding='utf-8') as reader:
164164
return yaml.load(reader, Loader=yaml.SafeLoader)
165165
except (yaml.YAMLError, IOError) as e:
166166
print('Unable to load YAML file {0}:\n{1}'.format(

bin/workshop_check.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ def main():
408408
reporter = Reporter()
409409
check_config(reporter, config_file)
410410
check_unwanted_files(root_dir, reporter)
411-
with open(index_file) as reader:
411+
with open(index_file, encoding='utf-8') as reader:
412412
data = reader.read()
413413
check_file(reporter, index_file, data)
414414
reporter.report()

0 commit comments

Comments
 (0)