Browse Source

Merge topic 'backport-sphinx-file-encoding' into release-3.26

e4f26edc1c Tests: Always load presets schema as UTF-8
fc2b60ca6b Sphinx: Modernize UTF-8 encoding handling when updating CMake.qhp
853f069103 Sphinx: Specify encoding when opening files for title extraction

Acked-by: Kitware Robot <[email protected]>
Merge-request: !8521
Brad King 2 years ago
parent
commit
b50caaf96a

+ 3 - 3
Tests/RunCMake/CMakePresets/validate_schema.py

@@ -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)

+ 3 - 2
Utilities/Sphinx/cmake.py

@@ -224,12 +224,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:

+ 4 - 4
Utilities/Sphinx/create_identifiers.py

@@ -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)