Skip to content

Commit a18a512

Browse files
committed
Extract whitelist to separate file.
1 parent abc915f commit a18a512

File tree

3 files changed

+40
-32
lines changed

3 files changed

+40
-32
lines changed

.dev/format.py

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,19 @@
55
import subprocess
66
import argparse
77

8-
WHITELIST = [
9-
"apps/3d_rec_framework",
10-
"apps/in_hand_scanner",
11-
"apps/include",
12-
"apps/modeler",
13-
"apps/src",
14-
"benchmarks",
15-
"2d",
16-
"geometry",
17-
"ml",
18-
"octree",
19-
"simulation",
20-
"stereo",
21-
"tracking",
22-
"registration",
23-
"gpu/containers",
24-
"gpu/segmentation"
25-
]
26-
278
EXTENSIONS = (".c", ".h", ".cpp", ".hpp", ".cxx", ".hxx", ".cu")
9+
WHITELIST_FILE = os.path.join(".dev", "whitelist.txt")
10+
11+
def load_whitelist():
12+
if not os.path.isfile(WHITELIST_FILE):
13+
print(f"Could not find whitelist file at {WHITELIST_FILE}")
14+
sys.exit(167)
15+
with open(WHITELIST_FILE, "r") as f:
16+
return [line.strip() for line in f if line.strip()]
2817

29-
def is_in_whitelist(file_path):
18+
def is_in_whitelist(file_path, whitelist):
3019
file_path = os.path.normpath(file_path)
31-
for w in WHITELIST:
20+
for w in whitelist:
3221
w_norm = os.path.normpath(w)
3322
if os.path.commonpath([file_path, w_norm]) == w_norm or file_path.startswith(w_norm + os.sep):
3423
return True
@@ -55,17 +44,18 @@ def main():
5544
)
5645
args = parser.parse_args()
5746

47+
whitelist = load_whitelist()
5848
manual_mode = len(args.files) == 1 and args.files[0] == "."
5949

6050
if manual_mode:
6151
all_files = []
62-
for rel_path in WHITELIST:
52+
for rel_path in whitelist:
6353
abs_path = os.path.join(os.getcwd(), rel_path)
6454
all_files.extend(find_files(abs_path))
6555
else:
6656
all_files = [
6757
f for f in args.files
68-
if f.endswith(EXTENSIONS) and os.path.isfile(f) and is_in_whitelist(f)
58+
if f.endswith(EXTENSIONS) and os.path.isfile(f) and is_in_whitelist(f, whitelist)
6959
]
7060

7161
all_files = list(set(all_files)) # Remove duplicates

.dev/format.sh

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
# $ sh /pcl/format.sh `which clang-format` /pcl
88

99
format() {
10-
# don't use a directory with whitespace
11-
local whitelist="apps/3d_rec_framework apps/in_hand_scanner apps/include apps/modeler apps/src benchmarks 2d geometry ml octree simulation stereo tracking registration gpu/containers gpu/segmentation"
12-
1310
local PCL_DIR="${2}"
1411
local formatter="${1}"
1512

@@ -18,17 +15,22 @@ format() {
1815
exit 166
1916
fi
2017

21-
# check for self
2218
if [ ! -f "${PCL_DIR}/.dev/format.sh" ]; then
2319
echo "Please ensure that PCL_SOURCE_DIR is passed as the second argument"
2420
exit 166
2521
fi
2622

27-
for dir in ${whitelist}; do
23+
local whitelist_file="${PCL_DIR}/.dev/whitelist.txt"
24+
if [ ! -f "${whitelist_file}" ]; then
25+
echo "Could not find whitelist file at ${whitelist_file}"
26+
exit 167
27+
fi
28+
29+
while IFS= read -r dir || [ -n "$dir" ]; do
30+
[ -z "$dir" ] && continue
2831
path=${PCL_DIR}/${dir}
29-
find ${path} -type f -iname *.[ch] -o -iname *.[ch]pp -o -iname *.[ch]xx \
30-
-iname *.cu | xargs -n1 ${formatter} -i -style=file
31-
done
32+
find ${path} -type f \( -iname "*.[ch]" -o -iname "*.[ch]pp" -o -iname "*.[ch]xx" -o -iname "*.cu" \) | xargs -n1 ${formatter} -i -style=file
33+
done < "${whitelist_file}"
3234
}
3335

34-
format $@
36+
format "$@"

.dev/whitelist.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apps/3d_rec_framework
2+
apps/in_hand_scanner
3+
apps/include
4+
apps/modeler
5+
apps/src
6+
benchmarks
7+
2d
8+
geometry
9+
ml
10+
octree
11+
simulation
12+
stereo
13+
tracking
14+
registration
15+
gpu/containers
16+
gpu/segmentation

0 commit comments

Comments
 (0)