Merge topic 'python-file-encoding'

b855674f5d Tests: Always load presets schema as UTF-8
0de00b8b69 Sphinx: Modernize UTF-8 encoding handling when updating CMake.qhp
f0d6010cb5 Sphinx: Specify encoding when opening files for title extraction

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !8402
This commit is contained in:
Craig Scott
2023-04-09 10:59:05 +00:00
committed by Kitware Robot
3 changed files with 10 additions and 9 deletions

View File

@@ -4,13 +4,13 @@ import os.path
import sys
with open(sys.argv[1], "rb") as f:
contents = json.loads(f.read().decode("utf-8-sig"))
with open(sys.argv[1], "r", encoding="utf-8-sig") as f:
contents = json.load(f)
schema_file = os.path.join(
os.path.dirname(__file__),
"..", "..", "..", "Help", "manual", "presets", "schema.json")
with open(schema_file) as f:
with open(schema_file, "r", encoding="utf-8") as f:
schema = json.load(f)
jsonschema.validate(contents, schema)

View File

@@ -242,12 +242,13 @@ class CMakeTransform(Transform):
The cmake --help-*-list commands also depend on this convention.
Return the title or False if the document file does not exist.
"""
env = self.document.settings.env
settings = self.document.settings
env = settings.env
title = self.titles.get(docname)
if title is None:
fname = os.path.join(env.srcdir, docname+'.rst')
try:
f = open(fname, 'r')
f = open(fname, 'r', encoding=settings.input_encoding)
except IOError:
title = False
else:

View File

@@ -6,12 +6,12 @@ if len(sys.argv) != 2:
sys.exit(-1)
name = sys.argv[1] + "/CMake.qhp"
f = open(name, "rb")
f = open(name, "r", encoding="utf-8")
if not f:
sys.exit(-1)
lines = f.read().decode("utf-8").splitlines()
lines = f.read().splitlines()
if not lines:
sys.exit(-1)
@@ -47,5 +47,5 @@ for line in lines:
line = part1 + prefix + "id=\"" + domain_object_type + "/" + domain_object + "\" " + part2
newlines.append(line + "\n")
f = open(name, "wb")
f.writelines(map(lambda line: line.encode("utf-8"), newlines))
f = open(name, "w", encoding="utf-8")
f.writelines(newlines)