Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 43 additions & 13 deletions devel/bin/mccode-clangformat
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
)
Expand All @@ -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}')

Expand Down
2 changes: 2 additions & 0 deletions docs/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!)
Expand All @@ -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!)
Expand Down