Sprinkle open(..., encoding=utf-8) (#48006)
Add missing encoding=utf-8 to various open calls. This makes files like spec.json, spack.yaml, spack.lock, config.yaml etc locale independent w.r.t. text encoding. In practice this is not often an issue since Python 3.7, where the C locale is promoted to C.UTF-8. But it's better to enforce UTF-8 explicitly, since there is no guarantee text files are written in the right encoding. Also avoid opening in text mode if it can be avoided.
This commit is contained in:
@@ -32,7 +32,7 @@ def find_logs(prefix, filename):
|
||||
# Look in the CWD for logs
|
||||
local_log_path = os.path.join(os.getcwd(), args.log)
|
||||
if os.path.exists(local_log_path):
|
||||
with open(local_log_path) as fd:
|
||||
with open(local_log_path, encoding="utf-8") as fd:
|
||||
data.append(json.load(fd))
|
||||
|
||||
# Look in the list of prefixes for logs
|
||||
@@ -42,9 +42,9 @@ def find_logs(prefix, filename):
|
||||
print(f" * found {len(logs)} logs")
|
||||
for log in logs:
|
||||
print(f" * appending data for {log}")
|
||||
with open(log) as fd:
|
||||
with open(log, encoding="utf-8") as fd:
|
||||
data.append(json.load(fd))
|
||||
|
||||
print(f"Writing {args.output_file}")
|
||||
with open(args.output_file, "w") as fd:
|
||||
with open(args.output_file, "w", encoding="utf-8") as fd:
|
||||
json.dump(data, fd)
|
||||
|
Reference in New Issue
Block a user