From b8f210cc7d89cb2150efd48b9cfde52b3b11d6a3 Mon Sep 17 00:00:00 2001 From: Peter Willendrup Date: Sat, 21 Feb 2026 12:35:38 +0100 Subject: [PATCH 1/2] Add -f filename to process single files and add --verbose output --- devel/bin/mccode-clangformat | 56 +++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/devel/bin/mccode-clangformat b/devel/bin/mccode-clangformat index a1f1330f1b..232504bbbc 100755 --- a/devel/bin/mccode-clangformat +++ b/devel/bin/mccode-clangformat @@ -7,7 +7,7 @@ only inside %{ %} sections using clang-format with repository .clang-format style, keeping delimiters on their own lines. Usage: - python mccode-clangformat.py [--repo PATH] [--file FILTER] [--clang-format PATH] [--check] + python mccode-clangformat.py [--repo PATH] [--filter FILTER] [--clang-format PATH] [--check] """ import argparse import os @@ -217,16 +217,21 @@ def main(): ap = argparse.ArgumentParser( description='Format code inside McCode %{ %} blocks using repository .clang-format' ) - ap.add_argument('--repo', '-r', default='.', help='Repo path (default: current dir)') - ap.add_argument('--file', '-f', default=None, help='Only process files matching this label') + ap.add_argument('--repo', '-r', default=None, help='Repo path') + ap.add_argument('--filter', '-F', default=None, help='Only process files matching this filtering label') + ap.add_argument('--file', '-f', default=None, help='Process this file only') + ap.add_argument('--verbose', '-v', action='store_true', help='Show progress messages') + ap.add_argument('--clang-format', '-c', default=None, help='Path to clang-format executable') ap.add_argument('--check', action='store_true', help="Check only; don't write files") args = ap.parse_args() - root = Path(args.repo).resolve() - if not root.exists(): - print(f'Repo path not found: {root}', file=sys.stderr) - sys.exit(2) + root=None + if args.repo: + root = Path(args.repo).resolve() + if not root.exists(): + print(f'Repo path not found: {root}', file=sys.stderr) + sys.exit(2) # Warn if no .clang-format file is found in this repo tree @@ -250,16 +255,42 @@ def main(): clang_path = ensure_clang_format(args.clang_format) - files = find_files(root,args.file) - if not files: - print('No .instr or .comp files found.', file=sys.stderr) + if args.file and root: + print('Incompatible input args: Please use EITHER -f some/file or -r directory/to/traverse', file=sys.stderr) sys.exit(1) any_changed = False failures = [] - for f in files: + if root: + files = find_files(root,args.filter) + if not files: + print('No .instr or .comp files found in ' + root, file=sys.stderr) + sys.exit(1) + + for f in files: + if args.verbose: + print('Processing ' + str(f)) + try: + changed, msg = process_file( + f, clang_path=clang_path, style_file=style_file, check_only=args.check + ) + if msg: + failures.append(msg) + if changed: + any_changed = True + print(f'Changed: {f}') + except FileNotFoundError: + failures.append('clang-format executable not found.') + break + except Exception as e: + failures.append(f'Error processing {f}: {e}') + + if args.file: try: + f=Path(args.file) + if args.verbose: + print('Processing ' + str(f)) changed, msg = process_file( f, clang_path=clang_path, style_file=style_file, check_only=args.check ) @@ -269,8 +300,7 @@ def main(): any_changed = True print(f'Changed: {f}') except FileNotFoundError: - failures.append('clang-format executable not found.') - break + failures.append('file not found.') except Exception as e: failures.append(f'Error processing {f}: {e}') From 3af12b0f344c2ceb2dbbdab8edb6dbbe630c9273 Mon Sep 17 00:00:00 2001 From: Peter Willendrup Date: Sat, 21 Feb 2026 12:41:12 +0100 Subject: [PATCH 2/2] Add mccode-clangformat in the contrib checklist --- docs/pull_request_template.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/pull_request_template.md b/docs/pull_request_template.md index 64db5936c6..816b9e5ca6 100644 --- a/docs/pull_request_template.md +++ b/docs/pull_request_template.md @@ -15,6 +15,7 @@ _Please describe what OS you developed and tested your additions on, and if any * [ ] I have used the `mcdoc` utility and **rendered** a reasonable documentation page for the component (please attach as screenshot in comments!) * [ ] I have ensured that basic use of the component is OK (e.g. an instrument using it compiles?) * [ ] I have used the `mctest` utility to **test** one or more instruments making use of the component (please attach `mcviewtest` report as screenshot in comments) + * [ ] I have used the `mccode-clangformat` tool to apply the standard McCode component indentation scheme * [ ] I have used the `mcrun --c-lint` "linter" and followed advice to remove most / all warnings that are raised * ### My contribution includes patches to an **existing** instrument file * [ ] I have used the `mcdoc` utility and **rendered** a reasonable documentation page for the instrument (please attach as screenshot in comments!) @@ -26,6 +27,7 @@ _Please describe what OS you developed and tested your additions on, and if any * [ ] I have used the `mcdoc` utility and **rendered** a reasonable documentation page for the component (please attach as screenshot in comments!) * [ ] I have ensured that basic use of the component is OK (e.g. an instrument using it compiles?) * [ ] I have included a corresponding **example** instrument and will fill in the **new instrument** section below + * [ ] I have used the `mccode-clangformat` tool to apply the standard McCode component indentation scheme * [ ] My new component is added within the `contrib` component category * ### My contribution includes a **new instrument** file * [ ] I have used the `mcdoc` utility and **rendered** a reasonable documentation page for the instrument (please attach as screenshot in comments!)