From 76eed5c65a4cab6b2da73f5e2fcbdc9c5fdad8eb Mon Sep 17 00:00:00 2001 From: Iliya Katueshenock Date: Fri, 23 Aug 2024 09:53:47 +1000 Subject: [PATCH] Fix clang-format & autopep8 do extra work when nothing to operate on When passing `.py` paths to the format command, clang-format paths would be empty and operate on all paths. Resolve by detecting cases when there is nothing to format. Ref: !126055 --- tools/utils_maintenance/autopep8_format_paths.py | 6 +++++- tools/utils_maintenance/clang_format_paths.py | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/utils_maintenance/autopep8_format_paths.py b/tools/utils_maintenance/autopep8_format_paths.py index f0e10a1da69..9f92679a63d 100755 --- a/tools/utils_maintenance/autopep8_format_paths.py +++ b/tools/utils_maintenance/autopep8_format_paths.py @@ -276,8 +276,12 @@ def main() -> int: print("Using \"{:s}\", ({:s})...".format(autopep8_source, version_str_from_tuple(version))) use_default_paths = not (bool(args.paths) or bool(args.changed_only)) - paths = compute_paths(args.paths, use_default_paths) + # Check if user-defined paths exclude all Python sources. + if args.paths and not paths: + print("Skip autopep8: no target to format") + return 0 + print("Operating on:" + (" ({:d} changed paths)".format(len(paths)) if args.changed_only else "")) for p in paths: print(" ", p) diff --git a/tools/utils_maintenance/clang_format_paths.py b/tools/utils_maintenance/clang_format_paths.py index f8143b988d7..8026141f572 100755 --- a/tools/utils_maintenance/clang_format_paths.py +++ b/tools/utils_maintenance/clang_format_paths.py @@ -234,8 +234,12 @@ def main() -> int: args = argparse_create().parse_args() use_default_paths = not (bool(args.paths) or bool(args.changed_only)) - paths = compute_paths(args.paths, use_default_paths) + # Check if user-defined paths exclude all clang-format sources. + if args.paths and not paths: + print("Skip clang-format: no target to format") + return 0 + print("Operating on:" + (" ({:d} changed paths)".format(len(paths)) if args.changed_only else "")) for p in paths: print(" ", p)