summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorPhilip Withnall <pwithnall@endlessos.org>2022-10-14 18:11:36 +0100
committerPhilip Withnall <pwithnall@endlessos.org>2022-10-14 18:15:25 +0100
commitf8981e9b495ba7dd95e254745f11342a5e50d62f (patch)
treec2fb08ac9c3c2b51f0d959c89c5ad7d55d62ab71 /tools
parent24aaff658b0a25b6d0322b8275a769d892166cbd (diff)
downloadglib-f8981e9b495ba7dd95e254745f11342a5e50d62f.tar.gz
tools: Reformat gen-visibility-macros.py with black
This satisfies the style-check CI job.
Diffstat (limited to 'tools')
-rwxr-xr-xtools/gen-visibility-macros.py86
1 files changed, 57 insertions, 29 deletions
diff --git a/tools/gen-visibility-macros.py b/tools/gen-visibility-macros.py
index e47671323..a7a724816 100755
--- a/tools/gen-visibility-macros.py
+++ b/tools/gen-visibility-macros.py
@@ -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()