Skip to content

Commit

Permalink
Re-format format-script for C++ sources.
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiPashkin committed Jan 3, 2021
1 parent fba1168 commit 25bfddc
Showing 1 changed file with 25 additions and 29 deletions.
54 changes: 25 additions & 29 deletions scripts/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,32 @@

DIRECTORIES = [
os.path.join(
os.path.dirname(os.path.abspath(__file__)),
os.pardir,
"include"
os.path.dirname(os.path.abspath(__file__)), os.pardir, "include"
),
os.path.join(
os.path.dirname(os.path.abspath(__file__)),
os.pardir,
"src",
"cpp"
)
os.path.dirname(os.path.abspath(__file__)), os.pardir, "src", "cpp"
),
]


if __name__ == '__main__':
if __name__ == "__main__":
parser = argparse.ArgumentParser(
'format',
"format",
description="""
Format C++ sources using Clang-Format.
"""
""",
)
parser.add_argument(
'--check',
'-C',
"--check",
"-C",
help="Do not format files but check if formatting is needed and exit "
"with non-zero code if it is.",
action='store_true',
default=False
"with non-zero code if it is.",
action="store_true",
default=False,
)
parser.add_argument(
'files',
nargs='*',
"files",
nargs="*",
)
arguments = parser.parse_args()
filepaths = []
Expand All @@ -62,22 +57,23 @@
sys.exit(result.returncode)
with open(filepath) as file_handle:
actual_source = file_handle.read()
diff = '\n'.join(difflib.unified_diff(
result.stdout.decode().split('\n'),
actual_source.split('\n'),
'Formatted source',
f'Actual source ({filepath})',
lineterm=''
))
diff = "\n".join(
difflib.unified_diff(
result.stdout.decode().split("\n"),
actual_source.split("\n"),
"Formatted source",
f"Actual source ({filepath})",
lineterm="",
)
)
if diff:
print('Fail')
print("Fail")
print(diff, file=sys.stderr, flush=True)
sys.exit(1)
print('Ok')
print("Ok")
sys.exit(0)
else:
result = subprocess.run(
["clang-format", "-i", "-style=file"] + filepaths,
env=os.environ
["clang-format", "-i", "-style=file"] + filepaths, env=os.environ
)
sys.exit(result.returncode)

0 comments on commit 25bfddc

Please sign in to comment.