Skip to content

Commit 3ab309b

Browse files
committed
Add and use python for formatting. More cross platform than shell script.
1 parent d211233 commit 3ab309b

2 files changed

Lines changed: 80 additions & 1 deletion

File tree

.ci/azure-pipelines/formatting.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
- checkout: self
88
# find the commit hash on a quick non-forced update too
99
fetchDepth: 10
10-
- script: ./.dev/format.sh $(which clang-format) .
10+
- script: python ./.dev/format.py .
1111
displayName: 'Run clang-format'
1212
- script: git diff > formatting.patch
1313
displayName: 'Compute diff'

.dev/format.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import sys
5+
import subprocess
6+
7+
WHITELIST = [
8+
"apps/cloud_composer/include/pcl/apps/cloud_composer",
9+
"apps/cloud_composer/src/point_selectors",
10+
"apps/cloud_composer/tools",
11+
"apps/cloud_composer/src/cloud_composer.cpp",
12+
"apps/cloud_composer/src/cloud_viewer.cpp",
13+
"apps/cloud_composer/src/commands.cpp",
14+
"apps/cloud_composer/src/item_inspector.cpp",
15+
"apps/cloud_composer/src/items/cloud_composer_item.cpp",
16+
"apps/cloud_composer/src/items/fpfh_item.cpp",
17+
"apps/cloud_composer/src/main.cpp",
18+
"apps/cloud_composer/src/merge_selection.cpp",
19+
"apps/cloud_composer/src/properties_model.cpp",
20+
"apps/cloud_composer/src/signal_multiplexer.cpp",
21+
"apps/cloud_composer/src/tool_interface/abstract_tool.cpp",
22+
"apps/cloud_composer/src/toolbox_model.cpp",
23+
"apps/cloud_composer/src/transform_clouds.cpp",
24+
"apps/cloud_composer/src/work_queue.cpp",
25+
"apps/3d_rec_framework",
26+
"apps/in_hand_scanner",
27+
"apps/include",
28+
"apps/modeler",
29+
"apps/src",
30+
"benchmarks",
31+
"2d",
32+
"geometry",
33+
"ml",
34+
"octree",
35+
"simulation",
36+
"stereo",
37+
"tracking",
38+
"registration",
39+
"gpu/containers",
40+
"gpu/segmentation"
41+
]
42+
43+
EXTENSIONS = (".c", ".h", ".cpp", ".hpp", ".cxx", ".hxx", ".cu")
44+
45+
def find_files(path):
46+
if os.path.isfile(path):
47+
if path.endswith(EXTENSIONS):
48+
yield path
49+
elif os.path.isdir(path):
50+
for root, _, files in os.walk(path):
51+
for file in files:
52+
if file.endswith(EXTENSIONS):
53+
yield os.path.join(root, file)
54+
55+
def main():
56+
if len(sys.argv) != 2:
57+
print("Usage: format.py <PCL_SOURCE_DIR>")
58+
sys.exit(1)
59+
60+
pcl_dir = sys.argv[1]
61+
62+
if not os.path.isfile(os.path.join(pcl_dir, ".dev/format.py")):
63+
print("Please ensure that PCL_SOURCE_DIR is passed as the argument")
64+
sys.exit(166)
65+
66+
all_files = []
67+
for rel_path in WHITELIST:
68+
abs_path = os.path.join(pcl_dir, rel_path)
69+
all_files.extend(find_files(abs_path))
70+
71+
if not all_files:
72+
print("No files found to format.")
73+
sys.exit(0)
74+
75+
clang_format_cmd = ["pipx", "run", "clang-format==14.0.3", "-i", "-style=file"] + all_files
76+
subprocess.run(clang_format_cmd)
77+
78+
if __name__ == "__main__":
79+
main()

0 commit comments

Comments
 (0)