tools: Reformat gen-visibility-macros.py with black

This satisfies the style-check CI job.
This commit is contained in:
Philip Withnall 2022-10-14 18:11:36 +01:00
parent 24aaff658b
commit f8981e9b49

View File

@ -16,12 +16,15 @@ from pathlib import Path
def gen_versions_macros(args, current_minor_version):
with args.out_path.open('w', encoding='utf-8') as ofile, \
args.in_path.open('r', encoding='utf-8') as ifile:
with args.out_path.open("w", encoding="utf-8") as ofile, args.in_path.open(
"r", encoding="utf-8"
) as ifile:
for line in ifile.readlines():
if '@GLIB_VERSIONS@' in line:
if "@GLIB_VERSIONS@" in line:
for minor in range(2, current_minor_version + 2, 2):
ofile.write(textwrap.dedent(f'''\
ofile.write(
textwrap.dedent(
f"""\
/**
* GLIB_VERSION_2_{minor}:
*
@ -31,24 +34,33 @@ def gen_versions_macros(args, current_minor_version):
* Since: 2.{max(minor, 32)}
*/
#define GLIB_VERSION_2_{minor} (G_ENCODE_VERSION (2, {minor}))
'''))
"""
)
)
else:
ofile.write(line)
def gen_doc_sections(args, current_minor_version):
with args.out_path.open('w', encoding='utf-8') as ofile, \
args.in_path.open('r', encoding='utf-8') as ifile:
with args.out_path.open("w", encoding="utf-8") as ofile, args.in_path.open(
"r", encoding="utf-8"
) as ifile:
for line in ifile.readlines():
if '@GLIB_VERSIONS@' in line:
if "@GLIB_VERSIONS@" in line:
for minor in range(2, current_minor_version + 2, 2):
ofile.write(textwrap.dedent(f'''\
ofile.write(
textwrap.dedent(
f"""\
GLIB_VERSION_2_{minor}
'''))
"""
)
)
else:
ofile.write(line)
def gen_visibility_macros(args, current_minor_version):
'''
"""
Generates a set of macros for each minor stable version of GLib
- GLIB_VAR
@ -70,11 +82,13 @@ def gen_visibility_macros(args, current_minor_version):
- GLIB_UNAVAILABLE_STATIC_INLINE(maj,min)
The GLIB namespace can be replaced with one of GOBJECT, GIO, GMODULE.
'''
"""
ns = args.namespace
with args.out_path.open('w', encoding='utf-8') as f:
f.write(textwrap.dedent(f'''\
with args.out_path.open("w", encoding="utf-8") as f:
f.write(
textwrap.dedent(
f"""\
#pragma once
#if (defined(_WIN32) || defined(__CYGWIN__)) && !defined({ns}_STATIC_COMPILATION)
@ -109,9 +123,13 @@ def gen_visibility_macros(args, current_minor_version):
#define {ns}_UNAVAILABLE(maj,min) G_UNAVAILABLE(maj,min) _{ns}_EXTERN
#define {ns}_UNAVAILABLE_STATIC_INLINE(maj,min) G_UNAVAILABLE(maj,min)
#endif
'''))
"""
)
)
for minor in range(26, current_minor_version + 2, 2):
f.write(textwrap.dedent(f'''
f.write(
textwrap.dedent(
f"""
#if GLIB_VERSION_MIN_REQUIRED >= GLIB_VERSION_2_{minor}
#define {ns}_DEPRECATED_IN_2_{minor} {ns}_DEPRECATED
#define {ns}_DEPRECATED_IN_2_{minor}_FOR(f) {ns}_DEPRECATED_FOR (f)
@ -145,32 +163,42 @@ def gen_visibility_macros(args, current_minor_version):
#define {ns}_AVAILABLE_ENUMERATOR_IN_2_{minor}
#define {ns}_AVAILABLE_TYPE_IN_2_{minor}
#endif
'''))
"""
)
)
def main():
parser = argparse.ArgumentParser()
parser.add_argument('glib_version', help='Current GLib version')
parser.add_argument("glib_version", help="Current GLib version")
subparsers = parser.add_subparsers()
versions_parser = subparsers.add_parser('versions-macros', help='Generate versions macros')
versions_parser.add_argument('in_path', help='input file', type=Path)
versions_parser.add_argument('out_path', help='output file', type=Path)
versions_parser = subparsers.add_parser(
"versions-macros", help="Generate versions macros"
)
versions_parser.add_argument("in_path", help="input file", type=Path)
versions_parser.add_argument("out_path", help="output file", type=Path)
versions_parser.set_defaults(func=gen_versions_macros)
doc_parser = subparsers.add_parser('doc-sections', help='Generate glib-sections.txt')
doc_parser.add_argument('in_path', help='input file', type=Path)
doc_parser.add_argument('out_path', help='output file', type=Path)
doc_parser = subparsers.add_parser(
"doc-sections", help="Generate glib-sections.txt"
)
doc_parser.add_argument("in_path", help="input file", type=Path)
doc_parser.add_argument("out_path", help="output file", type=Path)
doc_parser.set_defaults(func=gen_doc_sections)
visibility_parser = subparsers.add_parser('visibility-macros', help='Generate visibility macros')
visibility_parser.add_argument('namespace', help='Macro namespace')
visibility_parser.add_argument('out_path', help='output file', type=Path)
visibility_parser = subparsers.add_parser(
"visibility-macros", help="Generate visibility macros"
)
visibility_parser.add_argument("namespace", help="Macro namespace")
visibility_parser.add_argument("out_path", help="output file", type=Path)
visibility_parser.set_defaults(func=gen_visibility_macros)
args = parser.parse_args()
version = [int(i) for i in args.glib_version.split('.')]
version = [int(i) for i in args.glib_version.split(".")]
assert version[0] == 2
args.func(args, version[1])
if __name__ == '__main__':
if __name__ == "__main__":
main()