From a16b6048438b198c8d9109a1ef169e5331cc5fca Mon Sep 17 00:00:00 2001 From: Nils Dijk Date: Tue, 7 Nov 2023 12:18:07 +0000 Subject: [PATCH] format include grouping script --- ci/include-grouping.py | 108 +++++++++++++++++++++-------------------- 1 file changed, 56 insertions(+), 52 deletions(-) diff --git a/ci/include-grouping.py b/ci/include-grouping.py index 09adb9bdb..e5bc4fff2 100755 --- a/ci/include-grouping.py +++ b/ci/include-grouping.py @@ -6,18 +6,19 @@ import os import sys + def main(args): if len(args) < 2: print("Usage: include-grouping.py ") return - + file = args[1] if not os.path.isfile(file): print("File does not exist", file=sys.stderr) return sys.exit(1) - with open(file, 'r') as f: - with open(file + ".tmp", 'w') as out_file: + with open(file, "r") as f: + with open(file + ".tmp", "w") as out_file: lines = f.readlines() includes = [] skipped_lines = [] @@ -36,77 +37,79 @@ def main(args): # print skipped lines for skipped_line in skipped_lines: - print(skipped_line, end='', file=out_file) + print(skipped_line, end="", file=out_file) skipped_lines = [] - print(line, end='', file=out_file) + print(line, end="", file=out_file) # move out_file to file os.rename(file + ".tmp", file) pass + def print_sorted_includes(includes, file=sys.stdout): default_group_key = 1 groups = {} matches = [ - { - "name": "system includes", - "matcher": lambda x: x.startswith('<'), - "group_key": -2, - "priority": 0 - }, - { - "name": "naked postgres includes", - "matcher": lambda x: not '/' in x, - "group_key": 0, - "priority": 9 - }, - { - "name": "postgres.h", - "list": ['"postgres.h"'], - "group_key": -1, - "priority": -1 - }, - { - "name": "naked citus inlcudes", - "list": ['"citus_version.h"', '"pg_version_compat.h"'], - "group_key": 3, - "priority": 0 - }, - { - "name": "positional citus includes", - "list": ['"distributed/pg_version_constants.h"'], - "group_key": 4, - "priority": 0 - }, - { - "name": "columnar includes", - "matcher": lambda x: x.startswith('"columnar/'), - "group_key": 5, - "priority": 1 - }, - { - "name": "distributed includes", - "matcher": lambda x: x.startswith('"distributed/'), - "group_key": 6, - "priority": 1 - }] + { + "name": "system includes", + "matcher": lambda x: x.startswith("<"), + "group_key": -2, + "priority": 0, + }, + { + "name": "naked postgres includes", + "matcher": lambda x: not "/" in x, + "group_key": 0, + "priority": 9, + }, + { + "name": "postgres.h", + "list": ['"postgres.h"'], + "group_key": -1, + "priority": -1, + }, + { + "name": "naked citus inlcudes", + "list": ['"citus_version.h"', '"pg_version_compat.h"'], + "group_key": 3, + "priority": 0, + }, + { + "name": "positional citus includes", + "list": ['"distributed/pg_version_constants.h"'], + "group_key": 4, + "priority": 0, + }, + { + "name": "columnar includes", + "matcher": lambda x: x.startswith('"columnar/'), + "group_key": 5, + "priority": 1, + }, + { + "name": "distributed includes", + "matcher": lambda x: x.startswith('"distributed/'), + "group_key": 6, + "priority": 1, + }, + ] matches.sort(key=lambda x: x["priority"]) - common_system_include_error_prefixes = ['