address small feedback

pull/7326/head
Nils Dijk 2023-11-16 14:20:10 +00:00
parent c1ff029460
commit 8eb3ff92e4
No known key found for this signature in database
GPG Key ID: CA1177EF9434F241
1 changed files with 8 additions and 12 deletions

View File

@ -7,7 +7,7 @@ $ git ls-files \
| grep 'citus-style: set' \ | grep 'citus-style: set' \
| awk '{print $1}' \ | awk '{print $1}' \
| cut -d':' -f1 \ | cut -d':' -f1 \
| xargs -n1 ./ci/include-grouping.py | xargs -n1 ./ci/include_grouping.py
""" """
import collections import collections
@ -17,17 +17,15 @@ import sys
def main(args): def main(args):
if len(args) < 2: if len(args) < 2:
print("Usage: include-grouping.py <file>") print("Usage: include_grouping.py <file>")
return return
file = args[1] file = args[1]
if not os.path.isfile(file): if not os.path.isfile(file):
print("File does not exist", file=sys.stderr) sys.exit(f"File '{file}' does not exist")
return sys.exit(1)
with open(file, "r") as f: with open(file, "r") as in_file:
with open(file + ".tmp", "w") as out_file: with open(file + ".tmp", "w") as out_file:
lines = f.readlines()
includes = [] includes = []
skipped_lines = [] skipped_lines = []
@ -35,7 +33,7 @@ def main(args):
# This implicitly keeps separation of any #include lines that are contained in # This implicitly keeps separation of any #include lines that are contained in
# an #ifdef, because it will order the #include lines inside and after the # an #ifdef, because it will order the #include lines inside and after the
# #ifdef completely separately. # #ifdef completely separately.
for line in lines: for line in in_file:
# if a line starts with #include we don't want to print it yet, instead we # if a line starts with #include we don't want to print it yet, instead we
# want to collect all consecutive #include lines # want to collect all consecutive #include lines
if line.startswith("#include"): if line.startswith("#include"):
@ -58,17 +56,15 @@ def main(args):
print_sorted_includes(includes, file=out_file) print_sorted_includes(includes, file=out_file)
includes = [] includes = []
# print any skipped lines # print any skipped lines
print("".join(skipped_lines), end="", file=out_file) print("".join(skipped_lines), end="", file=out_file)
skipped_lines = [] skipped_lines = []
print(line, end="", file=out_file) print(line, end="", file=out_file)
# move out_file to file # move out_file to file
os.rename(file + ".tmp", file) os.rename(file + ".tmp", file)
pass
def print_sorted_includes(includes, file=sys.stdout): def print_sorted_includes(includes, file=sys.stdout):
default_group_key = 1 default_group_key = 1