Mesa (main): python: drop explicit output_encoding='utf-8' in mako templates

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sat Aug 14 22:06:58 UTC 2021


Module: Mesa
Branch: main
Commit: 4d9acfa5331be6140e84badff7a232dbf07b69b4
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=4d9acfa5331be6140e84badff7a232dbf07b69b4

Author: Eric Engestrom <eric at engestrom.ch>
Date:   Sat Aug  7 11:36:38 2021 +0100

python: drop explicit output_encoding='utf-8' in mako templates

Python 3 handles unicode strings by default, so we can drop all that.

Suggested-by: Dylan Baker <dylan at pnwbakers.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3674>

---

 src/compiler/nir/nir_intrinsics_c.py         | 4 ++--
 src/compiler/nir/nir_intrinsics_h.py         | 4 ++--
 src/compiler/nir/nir_intrinsics_indices_h.py | 4 ++--
 src/freedreno/isa/decode.py                  | 4 ++--
 src/freedreno/isa/encode.py                  | 4 ++--
 src/gallium/auxiliary/util/u_trace.py        | 8 ++++----
 src/intel/genxml/gen_bits_header.py          | 4 ++--
 src/intel/isl/gen_format_layout.py           | 5 ++---
 src/util/driconf_static.py                   | 4 ++--
 src/vulkan/util/gen_enum_to_str.py           | 8 +++-----
 src/vulkan/util/vk_dispatch_table_gen.py     | 8 ++++----
 src/vulkan/util/vk_entrypoints_gen.py        | 8 ++++----
 12 files changed, 31 insertions(+), 34 deletions(-)

diff --git a/src/compiler/nir/nir_intrinsics_c.py b/src/compiler/nir/nir_intrinsics_c.py
index 87e729bbcd8..79d69df280e 100644
--- a/src/compiler/nir/nir_intrinsics_c.py
+++ b/src/compiler/nir/nir_intrinsics_c.py
@@ -78,8 +78,8 @@ def main():
     args = parser.parse_args()
 
     path = os.path.join(args.outdir, 'nir_intrinsics.c')
-    with open(path, 'wb') as f:
-        f.write(Template(template, output_encoding='utf-8').render(
+    with open(path, 'w') as f:
+        f.write(Template(template).render(
             INTR_OPCODES=INTR_OPCODES, INTR_INDICES=INTR_INDICES,
             reduce=reduce, operator=operator))
 
diff --git a/src/compiler/nir/nir_intrinsics_h.py b/src/compiler/nir/nir_intrinsics_h.py
index 6941f233827..e4ebf3489b6 100644
--- a/src/compiler/nir/nir_intrinsics_h.py
+++ b/src/compiler/nir/nir_intrinsics_h.py
@@ -61,8 +61,8 @@ def main():
     args = parser.parse_args()
 
     path = os.path.join(args.outdir, 'nir_intrinsics.h')
-    with open(path, 'wb') as f:
-        f.write(Template(template, output_encoding='utf-8').render(INTR_OPCODES=INTR_OPCODES, INTR_INDICES=INTR_INDICES))
+    with open(path, 'w') as f:
+        f.write(Template(template).render(INTR_OPCODES=INTR_OPCODES, INTR_INDICES=INTR_INDICES))
 
 if __name__ == '__main__':
     main()
diff --git a/src/compiler/nir/nir_intrinsics_indices_h.py b/src/compiler/nir/nir_intrinsics_indices_h.py
index fd39e41bc9c..ff5bcdabfb0 100644
--- a/src/compiler/nir/nir_intrinsics_indices_h.py
+++ b/src/compiler/nir/nir_intrinsics_indices_h.py
@@ -86,8 +86,8 @@ def main():
     args = parser.parse_args()
 
     path = os.path.join(args.outdir, 'nir_intrinsics_indices.h')
-    with open(path, 'wb') as f:
-        f.write(Template(template, output_encoding='utf-8').render(INTR_INDICES=INTR_INDICES))
+    with open(path, 'w') as f:
+        f.write(Template(template).render(INTR_INDICES=INTR_INDICES))
 
 if __name__ == '__main__':
     main()
diff --git a/src/freedreno/isa/decode.py b/src/freedreno/isa/decode.py
index e4a2b949f58..0e459c69921 100644
--- a/src/freedreno/isa/decode.py
+++ b/src/freedreno/isa/decode.py
@@ -194,5 +194,5 @@ dst = sys.argv[2]
 
 isa = ISA(xml)
 
-with open(dst, 'wb') as f:
-    f.write(Template(template, output_encoding='utf-8').render(isa=isa))
+with open(dst, 'w') as f:
+    f.write(Template(template).render(isa=isa))
diff --git a/src/freedreno/isa/encode.py b/src/freedreno/isa/encode.py
index 699d5c9b660..791450990fb 100644
--- a/src/freedreno/isa/encode.py
+++ b/src/freedreno/isa/encode.py
@@ -558,5 +558,5 @@ dst = sys.argv[2]
 isa = ISA(xml)
 s = State(isa)
 
-with open(dst, 'wb') as f:
-    f.write(Template(template, output_encoding='utf-8').render(s=s))
+with open(dst, 'w') as f:
+    f.write(Template(template).render(s=s))
diff --git a/src/gallium/auxiliary/util/u_trace.py b/src/gallium/auxiliary/util/u_trace.py
index 9b1f87eff83..67470a8dd96 100644
--- a/src/gallium/auxiliary/util/u_trace.py
+++ b/src/gallium/auxiliary/util/u_trace.py
@@ -246,16 +246,16 @@ void __trace_${trace_name}(struct u_trace *ut
 def utrace_generate(cpath, hpath):
     if cpath is not None:
         hdr = os.path.basename(cpath).rsplit('.', 1)[0] + '.h'
-        with open(cpath, 'wb') as f:
-            f.write(Template(src_template, output_encoding='utf-8').render(
+        with open(cpath, 'w') as f:
+            f.write(Template(src_template).render(
                 hdr=hdr,
                 HEADERS=HEADERS,
                 TRACEPOINTS=TRACEPOINTS))
 
     if hpath is not None:
         hdr = os.path.basename(hpath)
-        with open(hpath, 'wb') as f:
-            f.write(Template(hdr_template, output_encoding='utf-8').render(
+        with open(hpath, 'w') as f:
+            f.write(Template(hdr_template).render(
                 hdrname=hdr.rstrip('.h').upper(),
                 HEADERS=HEADERS,
                 TRACEPOINTS=TRACEPOINTS))
diff --git a/src/intel/genxml/gen_bits_header.py b/src/intel/genxml/gen_bits_header.py
index 1c1b24450ae..38901461af2 100644
--- a/src/intel/genxml/gen_bits_header.py
+++ b/src/intel/genxml/gen_bits_header.py
@@ -118,7 +118,7 @@ ${emit_per_gen_prop_func(field, 'start')}
 }
 #endif
 
-#endif /* ${guard} */""", output_encoding='utf-8')
+#endif /* ${guard} */""")
 
 class Gen(object):
 
@@ -324,7 +324,7 @@ def main():
         p.engines = set(engines)
         p.parse(source)
 
-    with open(pargs.output, 'wb') as f:
+    with open(pargs.output, 'w') as f:
         f.write(TEMPLATE.render(containers=containers, guard=pargs.cpp_guard))
 
 if __name__ == '__main__':
diff --git a/src/intel/isl/gen_format_layout.py b/src/intel/isl/gen_format_layout.py
index 2da004dd96d..dfc8a7e1825 100644
--- a/src/intel/isl/gen_format_layout.py
+++ b/src/intel/isl/gen_format_layout.py
@@ -28,8 +28,7 @@ import re
 from mako import template
 
 # Load the template and set the bytes encoding to be utf-8.
-TEMPLATE = template.Template(output_encoding='utf-8',
-                             text="""\
+TEMPLATE = template.Template(text="""\
 /* This file is autogenerated by gen_format_layout.py. DO NOT EDIT! */
 
 /*
@@ -280,7 +279,7 @@ def main():
     # This generator opens and writes the file itself, and it does so in bytes
     # mode. This solves the locale problem: Unicode can be rendered even
     # if the shell calling this script doesn't.
-    with open(args.out, 'wb') as f:
+    with open(args.out, 'w') as f:
         formats = [Format(l) for l in reader(args.csv)]
         try:
             # This basically does lazy evaluation and initialization, which
diff --git a/src/util/driconf_static.py b/src/util/driconf_static.py
index cd03d17508f..d806c2554b4 100644
--- a/src/util/driconf_static.py
+++ b/src/util/driconf_static.py
@@ -223,6 +223,6 @@ static const struct driconf_device *driconf[] = {
 xml = sys.argv[1]
 dst = sys.argv[2]
 
-with open(dst, 'wb') as f:
-    f.write(Template(template, output_encoding='utf-8').render(driconf=DriConf(xml)))
+with open(dst, 'w') as f:
+    f.write(Template(template).render(driconf=DriConf(xml)))
 
diff --git a/src/vulkan/util/gen_enum_to_str.py b/src/vulkan/util/gen_enum_to_str.py
index 5fff82d6f75..600a79fd2d8 100644
--- a/src/vulkan/util/gen_enum_to_str.py
+++ b/src/vulkan/util/gen_enum_to_str.py
@@ -104,8 +104,7 @@ C_TEMPLATE = Template(textwrap.dedent(u"""\
             unreachable("Undefined struct type.");
         }
     }
-    """),
-    output_encoding='utf-8')
+    """))
 
 H_TEMPLATE = Template(textwrap.dedent(u"""\
     /* Autogenerated file -- do not edit
@@ -144,8 +143,7 @@ H_TEMPLATE = Template(textwrap.dedent(u"""\
     } /* extern "C" */
     #endif
 
-    #endif"""),
-    output_encoding='utf-8')
+    #endif"""))
 
 
 class NamedFactory(object):
@@ -345,7 +343,7 @@ def main():
 
     for template, file_ in [(C_TEMPLATE, os.path.join(args.outdir, 'vk_enum_to_str.c')),
                             (H_TEMPLATE, os.path.join(args.outdir, 'vk_enum_to_str.h'))]:
-        with open(file_, 'wb') as f:
+        with open(file_, 'w') as f:
             f.write(template.render(
                 file=os.path.basename(__file__),
                 enums=enums,
diff --git a/src/vulkan/util/vk_dispatch_table_gen.py b/src/vulkan/util/vk_dispatch_table_gen.py
index 9caba3035c4..be0bd3c59d4 100644
--- a/src/vulkan/util/vk_dispatch_table_gen.py
+++ b/src/vulkan/util/vk_dispatch_table_gen.py
@@ -221,7 +221,7 @@ extern struct vk_device_dispatch_table vk_device_trampolines;
 #endif
 
 #endif /* VK_DISPATCH_TABLE_H */
-""", output_encoding='utf-8')
+""")
 
 TEMPLATE_C = Template(COPYRIGHT + """\
 /* This file generated from ${filename}, don't edit directly. */
@@ -667,7 +667,7 @@ struct vk_device_dispatch_table vk_device_trampolines = {
   % endif
 % endfor
 };
-""", output_encoding='utf-8')
+""")
 
 U32_MASK = 2**32 - 1
 
@@ -927,13 +927,13 @@ def main():
     # per entry point.
     try:
         if args.out_h:
-            with open(args.out_h, 'wb') as f:
+            with open(args.out_h, 'w') as f:
                 f.write(TEMPLATE_H.render(instance_entrypoints=instance_entrypoints,
                                           physical_device_entrypoints=physical_device_entrypoints,
                                           device_entrypoints=device_entrypoints,
                                           filename=os.path.basename(__file__)))
         if args.out_c:
-            with open(args.out_c, 'wb') as f:
+            with open(args.out_c, 'w') as f:
                 f.write(TEMPLATE_C.render(instance_entrypoints=instance_entrypoints,
                                           physical_device_entrypoints=physical_device_entrypoints,
                                           device_entrypoints=device_entrypoints,
diff --git a/src/vulkan/util/vk_entrypoints_gen.py b/src/vulkan/util/vk_entrypoints_gen.py
index a663d10e114..a8f50c71c24 100644
--- a/src/vulkan/util/vk_entrypoints_gen.py
+++ b/src/vulkan/util/vk_entrypoints_gen.py
@@ -99,7 +99,7 @@ extern const struct vk_device_entrypoint_table ${p}_device_entrypoints;
 #endif
 
 #endif /* ${guard} */
-""", output_encoding='utf-8')
+""")
 
 TEMPLATE_C = Template(COPYRIGHT + """
 /* This file generated from ${filename}, don't edit directly. */
@@ -159,7 +159,7 @@ const struct vk_${type}_entrypoint_table ${p}_${type}_entrypoints = {
 ${entrypoint_table('instance', instance_entrypoints, instance_prefixes)}
 ${entrypoint_table('physical_device', physical_device_entrypoints, physical_device_prefixes)}
 ${entrypoint_table('device', device_entrypoints, device_prefixes)}
-""", output_encoding='utf-8')
+""")
 
 def get_entrypoints_defines(doc):
     """Maps entry points to extension defines."""
@@ -236,10 +236,10 @@ def main():
     # For outputting entrypoints.h we generate a anv_EntryPoint() prototype
     # per entry point.
     try:
-        with open(args.out_h, 'wb') as f:
+        with open(args.out_h, 'w') as f:
             guard = os.path.basename(args.out_h).replace('.', '_').upper()
             f.write(TEMPLATE_H.render(guard=guard, **environment))
-        with open(args.out_c, 'wb') as f:
+        with open(args.out_c, 'w') as f:
             f.write(TEMPLATE_C.render(**environment))
 
     except Exception:



More information about the mesa-commit mailing list