|
| 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