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:

committed by
Marge Bot

parent
3f99ff8a0e
commit
4d9acfa533
@@ -78,8 +78,8 @@ def main():
|
|||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
path = os.path.join(args.outdir, 'nir_intrinsics.c')
|
path = os.path.join(args.outdir, 'nir_intrinsics.c')
|
||||||
with open(path, 'wb') as f:
|
with open(path, 'w') as f:
|
||||||
f.write(Template(template, output_encoding='utf-8').render(
|
f.write(Template(template).render(
|
||||||
INTR_OPCODES=INTR_OPCODES, INTR_INDICES=INTR_INDICES,
|
INTR_OPCODES=INTR_OPCODES, INTR_INDICES=INTR_INDICES,
|
||||||
reduce=reduce, operator=operator))
|
reduce=reduce, operator=operator))
|
||||||
|
|
||||||
|
@@ -61,8 +61,8 @@ def main():
|
|||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
path = os.path.join(args.outdir, 'nir_intrinsics.h')
|
path = os.path.join(args.outdir, 'nir_intrinsics.h')
|
||||||
with open(path, 'wb') as f:
|
with open(path, 'w') as f:
|
||||||
f.write(Template(template, output_encoding='utf-8').render(INTR_OPCODES=INTR_OPCODES, INTR_INDICES=INTR_INDICES))
|
f.write(Template(template).render(INTR_OPCODES=INTR_OPCODES, INTR_INDICES=INTR_INDICES))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
@@ -86,8 +86,8 @@ def main():
|
|||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
path = os.path.join(args.outdir, 'nir_intrinsics_indices.h')
|
path = os.path.join(args.outdir, 'nir_intrinsics_indices.h')
|
||||||
with open(path, 'wb') as f:
|
with open(path, 'w') as f:
|
||||||
f.write(Template(template, output_encoding='utf-8').render(INTR_INDICES=INTR_INDICES))
|
f.write(Template(template).render(INTR_INDICES=INTR_INDICES))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
@@ -194,5 +194,5 @@ dst = sys.argv[2]
|
|||||||
|
|
||||||
isa = ISA(xml)
|
isa = ISA(xml)
|
||||||
|
|
||||||
with open(dst, 'wb') as f:
|
with open(dst, 'w') as f:
|
||||||
f.write(Template(template, output_encoding='utf-8').render(isa=isa))
|
f.write(Template(template).render(isa=isa))
|
||||||
|
@@ -558,5 +558,5 @@ dst = sys.argv[2]
|
|||||||
isa = ISA(xml)
|
isa = ISA(xml)
|
||||||
s = State(isa)
|
s = State(isa)
|
||||||
|
|
||||||
with open(dst, 'wb') as f:
|
with open(dst, 'w') as f:
|
||||||
f.write(Template(template, output_encoding='utf-8').render(s=s))
|
f.write(Template(template).render(s=s))
|
||||||
|
@@ -246,16 +246,16 @@ void __trace_${trace_name}(struct u_trace *ut
|
|||||||
def utrace_generate(cpath, hpath):
|
def utrace_generate(cpath, hpath):
|
||||||
if cpath is not None:
|
if cpath is not None:
|
||||||
hdr = os.path.basename(cpath).rsplit('.', 1)[0] + '.h'
|
hdr = os.path.basename(cpath).rsplit('.', 1)[0] + '.h'
|
||||||
with open(cpath, 'wb') as f:
|
with open(cpath, 'w') as f:
|
||||||
f.write(Template(src_template, output_encoding='utf-8').render(
|
f.write(Template(src_template).render(
|
||||||
hdr=hdr,
|
hdr=hdr,
|
||||||
HEADERS=HEADERS,
|
HEADERS=HEADERS,
|
||||||
TRACEPOINTS=TRACEPOINTS))
|
TRACEPOINTS=TRACEPOINTS))
|
||||||
|
|
||||||
if hpath is not None:
|
if hpath is not None:
|
||||||
hdr = os.path.basename(hpath)
|
hdr = os.path.basename(hpath)
|
||||||
with open(hpath, 'wb') as f:
|
with open(hpath, 'w') as f:
|
||||||
f.write(Template(hdr_template, output_encoding='utf-8').render(
|
f.write(Template(hdr_template).render(
|
||||||
hdrname=hdr.rstrip('.h').upper(),
|
hdrname=hdr.rstrip('.h').upper(),
|
||||||
HEADERS=HEADERS,
|
HEADERS=HEADERS,
|
||||||
TRACEPOINTS=TRACEPOINTS))
|
TRACEPOINTS=TRACEPOINTS))
|
||||||
|
@@ -118,7 +118,7 @@ ${emit_per_gen_prop_func(field, 'start')}
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* ${guard} */""", output_encoding='utf-8')
|
#endif /* ${guard} */""")
|
||||||
|
|
||||||
class Gen(object):
|
class Gen(object):
|
||||||
|
|
||||||
@@ -324,7 +324,7 @@ def main():
|
|||||||
p.engines = set(engines)
|
p.engines = set(engines)
|
||||||
p.parse(source)
|
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))
|
f.write(TEMPLATE.render(containers=containers, guard=pargs.cpp_guard))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@@ -28,8 +28,7 @@ import re
|
|||||||
from mako import template
|
from mako import template
|
||||||
|
|
||||||
# Load the template and set the bytes encoding to be utf-8.
|
# Load the template and set the bytes encoding to be utf-8.
|
||||||
TEMPLATE = template.Template(output_encoding='utf-8',
|
TEMPLATE = template.Template(text="""\
|
||||||
text="""\
|
|
||||||
/* This file is autogenerated by gen_format_layout.py. DO NOT EDIT! */
|
/* 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
|
# 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
|
# mode. This solves the locale problem: Unicode can be rendered even
|
||||||
# if the shell calling this script doesn't.
|
# 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)]
|
formats = [Format(l) for l in reader(args.csv)]
|
||||||
try:
|
try:
|
||||||
# This basically does lazy evaluation and initialization, which
|
# This basically does lazy evaluation and initialization, which
|
||||||
|
@@ -223,6 +223,6 @@ static const struct driconf_device *driconf[] = {
|
|||||||
xml = sys.argv[1]
|
xml = sys.argv[1]
|
||||||
dst = sys.argv[2]
|
dst = sys.argv[2]
|
||||||
|
|
||||||
with open(dst, 'wb') as f:
|
with open(dst, 'w') as f:
|
||||||
f.write(Template(template, output_encoding='utf-8').render(driconf=DriConf(xml)))
|
f.write(Template(template).render(driconf=DriConf(xml)))
|
||||||
|
|
||||||
|
@@ -104,8 +104,7 @@ C_TEMPLATE = Template(textwrap.dedent(u"""\
|
|||||||
unreachable("Undefined struct type.");
|
unreachable("Undefined struct type.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"""),
|
"""))
|
||||||
output_encoding='utf-8')
|
|
||||||
|
|
||||||
H_TEMPLATE = Template(textwrap.dedent(u"""\
|
H_TEMPLATE = Template(textwrap.dedent(u"""\
|
||||||
/* Autogenerated file -- do not edit
|
/* Autogenerated file -- do not edit
|
||||||
@@ -144,8 +143,7 @@ H_TEMPLATE = Template(textwrap.dedent(u"""\
|
|||||||
} /* extern "C" */
|
} /* extern "C" */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif"""),
|
#endif"""))
|
||||||
output_encoding='utf-8')
|
|
||||||
|
|
||||||
|
|
||||||
class NamedFactory(object):
|
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')),
|
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'))]:
|
(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(
|
f.write(template.render(
|
||||||
file=os.path.basename(__file__),
|
file=os.path.basename(__file__),
|
||||||
enums=enums,
|
enums=enums,
|
||||||
|
@@ -221,7 +221,7 @@ extern struct vk_device_dispatch_table vk_device_trampolines;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* VK_DISPATCH_TABLE_H */
|
#endif /* VK_DISPATCH_TABLE_H */
|
||||||
""", output_encoding='utf-8')
|
""")
|
||||||
|
|
||||||
TEMPLATE_C = Template(COPYRIGHT + """\
|
TEMPLATE_C = Template(COPYRIGHT + """\
|
||||||
/* This file generated from ${filename}, don't edit directly. */
|
/* This file generated from ${filename}, don't edit directly. */
|
||||||
@@ -667,7 +667,7 @@ struct vk_device_dispatch_table vk_device_trampolines = {
|
|||||||
% endif
|
% endif
|
||||||
% endfor
|
% endfor
|
||||||
};
|
};
|
||||||
""", output_encoding='utf-8')
|
""")
|
||||||
|
|
||||||
U32_MASK = 2**32 - 1
|
U32_MASK = 2**32 - 1
|
||||||
|
|
||||||
@@ -927,13 +927,13 @@ def main():
|
|||||||
# per entry point.
|
# per entry point.
|
||||||
try:
|
try:
|
||||||
if args.out_h:
|
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,
|
f.write(TEMPLATE_H.render(instance_entrypoints=instance_entrypoints,
|
||||||
physical_device_entrypoints=physical_device_entrypoints,
|
physical_device_entrypoints=physical_device_entrypoints,
|
||||||
device_entrypoints=device_entrypoints,
|
device_entrypoints=device_entrypoints,
|
||||||
filename=os.path.basename(__file__)))
|
filename=os.path.basename(__file__)))
|
||||||
if args.out_c:
|
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,
|
f.write(TEMPLATE_C.render(instance_entrypoints=instance_entrypoints,
|
||||||
physical_device_entrypoints=physical_device_entrypoints,
|
physical_device_entrypoints=physical_device_entrypoints,
|
||||||
device_entrypoints=device_entrypoints,
|
device_entrypoints=device_entrypoints,
|
||||||
|
@@ -99,7 +99,7 @@ extern const struct vk_device_entrypoint_table ${p}_device_entrypoints;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* ${guard} */
|
#endif /* ${guard} */
|
||||||
""", output_encoding='utf-8')
|
""")
|
||||||
|
|
||||||
TEMPLATE_C = Template(COPYRIGHT + """
|
TEMPLATE_C = Template(COPYRIGHT + """
|
||||||
/* This file generated from ${filename}, don't edit directly. */
|
/* 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('instance', instance_entrypoints, instance_prefixes)}
|
||||||
${entrypoint_table('physical_device', physical_device_entrypoints, physical_device_prefixes)}
|
${entrypoint_table('physical_device', physical_device_entrypoints, physical_device_prefixes)}
|
||||||
${entrypoint_table('device', device_entrypoints, device_prefixes)}
|
${entrypoint_table('device', device_entrypoints, device_prefixes)}
|
||||||
""", output_encoding='utf-8')
|
""")
|
||||||
|
|
||||||
def get_entrypoints_defines(doc):
|
def get_entrypoints_defines(doc):
|
||||||
"""Maps entry points to extension defines."""
|
"""Maps entry points to extension defines."""
|
||||||
@@ -236,10 +236,10 @@ def main():
|
|||||||
# For outputting entrypoints.h we generate a anv_EntryPoint() prototype
|
# For outputting entrypoints.h we generate a anv_EntryPoint() prototype
|
||||||
# per entry point.
|
# per entry point.
|
||||||
try:
|
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()
|
guard = os.path.basename(args.out_h).replace('.', '_').upper()
|
||||||
f.write(TEMPLATE_H.render(guard=guard, **environment))
|
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))
|
f.write(TEMPLATE_C.render(**environment))
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
|
Reference in New Issue
Block a user