Cleanup: use main functions to allow importing scripts

Support importing scripts without running their logic to
allow basic validation (see #130746).

Parts of !131037 were used.

Co-authored-by: Bastien Montagne <bastien@blender.org>
This commit is contained in:
Campbell Barton
2024-11-29 15:21:01 +11:00
parent b295fc9a9c
commit 273f48cd53
10 changed files with 331 additions and 265 deletions

View File

@@ -83,9 +83,15 @@ def sort_struct_lists(fn: str, data_src: str) -> str | None:
return None
run(
directories=[os.path.join(SOURCE_DIR, d) for d in SOURCE_DIRS],
is_text=lambda fn: fn.endswith(SOURCE_EXT),
text_operation=sort_struct_lists,
use_multiprocess=True,
)
def main() -> int:
run(
directories=[os.path.join(SOURCE_DIR, d) for d in SOURCE_DIRS],
is_text=lambda fn: fn.endswith(SOURCE_EXT),
text_operation=sort_struct_lists,
use_multiprocess=True,
)
return 0
if __name__ == "__main__":
sys.exit(main())

View File

@@ -84,9 +84,15 @@ def clean_structs(fn: str, data_src: str) -> str | None:
return None
run(
directories=[os.path.join(SOURCE_DIR, d) for d in SOURCE_DIRS],
is_text=lambda fn: fn.endswith(SOURCE_EXT),
text_operation=clean_structs,
use_multiprocess=False,
)
def main() -> int:
run(
directories=[os.path.join(SOURCE_DIR, d) for d in SOURCE_DIRS],
is_text=lambda fn: fn.endswith(SOURCE_EXT),
text_operation=clean_structs,
use_multiprocess=False,
)
return 0
if __name__ == "__main__":
sys.exit(main())

View File

@@ -93,9 +93,15 @@ def sort_cmake_file_lists(fn: str, data_src: str) -> str | None:
return None
run(
directories=[os.path.join(SOURCE_DIR, d) for d in SOURCE_DIRS],
is_text=lambda fn: fn.endswith("CMakeLists.txt"),
text_operation=sort_cmake_file_lists,
use_multiprocess=True,
)
def main() -> int:
run(
directories=[os.path.join(SOURCE_DIR, d) for d in SOURCE_DIRS],
is_text=lambda fn: fn.endswith("CMakeLists.txt"),
text_operation=sort_cmake_file_lists,
use_multiprocess=True,
)
return 0
if __name__ == "__main__":
sys.exit(main())