Skip to content

Commit e3be0c9

Browse files
committed
Formatting
1 parent 1e85938 commit e3be0c9

File tree

1 file changed

+67
-34
lines changed

1 file changed

+67
-34
lines changed

scripts/run-clang-format.py

+67-34
Original file line numberDiff line numberDiff line change
@@ -14,42 +14,64 @@
1414
#
1515

1616
from __future__ import print_function
17-
import sys
18-
import re
17+
18+
import argparse
1919
import os
20+
import re
2021
import subprocess
21-
import argparse
22+
import sys
2223
import tempfile
2324

24-
2525
EXPECTED_VERSION = "8.0.1"
2626
VERSION_REGEX = re.compile(r"clang-format version ([0-9.]+)")
27-
# NOTE: populate this list with more top-level dirs as we add more of them to the rmm repo
28-
DEFAULT_DIRS = ["src",
29-
"include",
30-
"tests",
31-
"benchmarks"]
27+
# NOTE: populate this list with more top-level dirs as we add more of them
28+
# to the rmm repo
29+
DEFAULT_DIRS = ["src", "include", "tests", "benchmarks"]
3230

3331

3432
def parse_args():
3533
argparser = argparse.ArgumentParser("Runs clang-format on a project")
36-
argparser.add_argument("-dstdir", type=str, default=None,
37-
help="Directory to store the temporary outputs of"
38-
" clang-format. If nothing is passed for this, then"
39-
" a temporary dir will be created using `mkdtemp`")
40-
argparser.add_argument("-exe", type=str, default="clang-format",
41-
help="Path to clang-format exe")
42-
argparser.add_argument("-inplace", default=False, action="store_true",
43-
help="Replace the source files itself.")
44-
argparser.add_argument("-regex", type=str,
45-
default=r"[.](cu|cuh|h|hpp|cpp)$",
46-
help="Regex string to filter in sources")
47-
argparser.add_argument("-ignore", type=str, default=r"cannylab/bh[.]cu$",
48-
help="Regex used to ignore files from matched list")
49-
argparser.add_argument("-v", dest="verbose", action="store_true",
50-
help="Print verbose messages")
51-
argparser.add_argument("dirs", type=str, nargs="*",
52-
help="List of dirs where to find sources")
34+
argparser.add_argument(
35+
"-dstdir",
36+
type=str,
37+
default=None,
38+
help="Directory to store the temporary outputs of"
39+
" clang-format. If nothing is passed for this, then"
40+
" a temporary dir will be created using `mkdtemp`",
41+
)
42+
argparser.add_argument(
43+
"-exe",
44+
type=str,
45+
default="clang-format",
46+
help="Path to clang-format exe",
47+
)
48+
argparser.add_argument(
49+
"-inplace",
50+
default=False,
51+
action="store_true",
52+
help="Replace the source files itself.",
53+
)
54+
argparser.add_argument(
55+
"-regex",
56+
type=str,
57+
default=r"[.](cu|cuh|h|hpp|cpp)$",
58+
help="Regex string to filter in sources",
59+
)
60+
argparser.add_argument(
61+
"-ignore",
62+
type=str,
63+
default=r"cannylab/bh[.]cu$",
64+
help="Regex used to ignore files from matched list",
65+
)
66+
argparser.add_argument(
67+
"-v",
68+
dest="verbose",
69+
action="store_true",
70+
help="Print verbose messages",
71+
)
72+
argparser.add_argument(
73+
"dirs", type=str, nargs="*", help="List of dirs where to find sources"
74+
)
5375
args = argparser.parse_args()
5476
args.regex_compiled = re.compile(args.regex)
5577
args.ignore_compiled = re.compile(args.ignore)
@@ -62,8 +84,10 @@ def parse_args():
6284
raise Exception("Failed to figure out clang-format version!")
6385
version = version.group(1)
6486
if version != EXPECTED_VERSION:
65-
raise Exception("clang-format exe must be v%s found '%s'" % \
66-
(EXPECTED_VERSION, version))
87+
raise Exception(
88+
"clang-format exe must be v%s found '%s'"
89+
% (EXPECTED_VERSION, version)
90+
)
6791
if len(args.dirs) == 0:
6892
args.dirs = DEFAULT_DIRS
6993
return args
@@ -108,8 +132,10 @@ def run_clang_format(src, dst, exe, verbose):
108132
if verbose:
109133
print("%s passed" % os.path.basename(src))
110134
except subprocess.CalledProcessError:
111-
print("%s failed! 'diff %s %s' will show formatting violations!" % \
112-
(os.path.basename(src), src, dst))
135+
print(
136+
"%s failed! 'diff %s %s' will show formatting violations!"
137+
% (os.path.basename(src), src, dst)
138+
)
113139
return False
114140
return True
115141

@@ -120,8 +146,13 @@ def main():
120146
if not os.path.exists(".git"):
121147
print("Error!! This needs to always be run from the root of repo")
122148
sys.exit(-1)
123-
all_files = list_all_src_files(args.regex_compiled, args.ignore_compiled,
124-
args.dirs, args.dstdir, args.inplace)
149+
all_files = list_all_src_files(
150+
args.regex_compiled,
151+
args.ignore_compiled,
152+
args.dirs,
153+
args.dstdir,
154+
args.inplace,
155+
)
125156
# actual format checker
126157
status = True
127158
for src, dst in all_files:
@@ -132,8 +163,10 @@ def main():
132163
print(" 1. Look at formatting differences above and fix them manually")
133164
print(" 2. Or run the below command to bulk-fix all these at once")
134165
print("Bulk-fix command: ")
135-
print(" python scripts/run-clang-format.py %s -inplace" % \
136-
" ".join(sys.argv[1:]))
166+
print(
167+
" python scripts/run-clang-format.py %s -inplace"
168+
% " ".join(sys.argv[1:])
169+
)
137170
sys.exit(-1)
138171
return
139172

0 commit comments

Comments
 (0)