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@pnwbakers.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3674>
This commit is contained in:
Eric Engestrom 2021-08-07 11:36:38 +01:00 committed by Marge Bot
parent 3f99ff8a0e
commit 4d9acfa533
12 changed files with 31 additions and 34 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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__':

View File

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

View File

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

View File

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

View File

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

View File

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