Skip to content

Commit 5d11656

Browse files
authored
Merge pull request #2334 from willend/main
Minor improvements to mccode-clangformat tool + update PR template
2 parents aeffc7c + 3af12b0 commit 5d11656

2 files changed

Lines changed: 45 additions & 13 deletions

File tree

devel/bin/mccode-clangformat

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ only inside %{ %} sections using clang-format with repository .clang-format
77
style, keeping delimiters on their own lines.
88
99
Usage:
10-
python mccode-clangformat.py [--repo PATH] [--file FILTER] [--clang-format PATH] [--check]
10+
python mccode-clangformat.py [--repo PATH] [--filter FILTER] [--clang-format PATH] [--check]
1111
"""
1212
import argparse
1313
import os
@@ -217,16 +217,21 @@ def main():
217217
ap = argparse.ArgumentParser(
218218
description='Format code inside McCode %{ %} blocks using repository .clang-format'
219219
)
220-
ap.add_argument('--repo', '-r', default='.', help='Repo path (default: current dir)')
221-
ap.add_argument('--file', '-f', default=None, help='Only process files matching this label')
220+
ap.add_argument('--repo', '-r', default=None, help='Repo path')
221+
ap.add_argument('--filter', '-F', default=None, help='Only process files matching this filtering label')
222+
ap.add_argument('--file', '-f', default=None, help='Process this file only')
223+
ap.add_argument('--verbose', '-v', action='store_true', help='Show progress messages')
224+
222225
ap.add_argument('--clang-format', '-c', default=None, help='Path to clang-format executable')
223226
ap.add_argument('--check', action='store_true', help="Check only; don't write files")
224227
args = ap.parse_args()
225228

226-
root = Path(args.repo).resolve()
227-
if not root.exists():
228-
print(f'Repo path not found: {root}', file=sys.stderr)
229-
sys.exit(2)
229+
root=None
230+
if args.repo:
231+
root = Path(args.repo).resolve()
232+
if not root.exists():
233+
print(f'Repo path not found: {root}', file=sys.stderr)
234+
sys.exit(2)
230235

231236
# Warn if no .clang-format file is found in this repo tree
232237

@@ -250,16 +255,42 @@ def main():
250255

251256
clang_path = ensure_clang_format(args.clang_format)
252257

253-
files = find_files(root,args.file)
254-
if not files:
255-
print('No .instr or .comp files found.', file=sys.stderr)
258+
if args.file and root:
259+
print('Incompatible input args: Please use EITHER -f some/file or -r directory/to/traverse', file=sys.stderr)
256260
sys.exit(1)
257261

258262
any_changed = False
259263
failures = []
260264

261-
for f in files:
265+
if root:
266+
files = find_files(root,args.filter)
267+
if not files:
268+
print('No .instr or .comp files found in ' + root, file=sys.stderr)
269+
sys.exit(1)
270+
271+
for f in files:
272+
if args.verbose:
273+
print('Processing ' + str(f))
274+
try:
275+
changed, msg = process_file(
276+
f, clang_path=clang_path, style_file=style_file, check_only=args.check
277+
)
278+
if msg:
279+
failures.append(msg)
280+
if changed:
281+
any_changed = True
282+
print(f'Changed: {f}')
283+
except FileNotFoundError:
284+
failures.append('clang-format executable not found.')
285+
break
286+
except Exception as e:
287+
failures.append(f'Error processing {f}: {e}')
288+
289+
if args.file:
262290
try:
291+
f=Path(args.file)
292+
if args.verbose:
293+
print('Processing ' + str(f))
263294
changed, msg = process_file(
264295
f, clang_path=clang_path, style_file=style_file, check_only=args.check
265296
)
@@ -269,8 +300,7 @@ def main():
269300
any_changed = True
270301
print(f'Changed: {f}')
271302
except FileNotFoundError:
272-
failures.append('clang-format executable not found.')
273-
break
303+
failures.append('file not found.')
274304
except Exception as e:
275305
failures.append(f'Error processing {f}: {e}')
276306

docs/pull_request_template.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ _Please describe what OS you developed and tested your additions on, and if any
1515
* [ ] I have used the `mcdoc` utility and **rendered** a reasonable documentation page for the component (please attach as screenshot in comments!)
1616
* [ ] I have ensured that basic use of the component is OK (e.g. an instrument using it compiles?)
1717
* [ ] 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)
18+
* [ ] I have used the `mccode-clangformat` tool to apply the standard McCode component indentation scheme
1819
* [ ] I have used the `mcrun --c-lint` "linter" and followed advice to remove most / all warnings that are raised
1920
* ### My contribution includes patches to an **existing** instrument file
2021
* [ ] 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
2627
* [ ] I have used the `mcdoc` utility and **rendered** a reasonable documentation page for the component (please attach as screenshot in comments!)
2728
* [ ] I have ensured that basic use of the component is OK (e.g. an instrument using it compiles?)
2829
* [ ] I have included a corresponding **example** instrument and will fill in the **new instrument** section below
30+
* [ ] I have used the `mccode-clangformat` tool to apply the standard McCode component indentation scheme
2931
* [ ] My new component is added within the `contrib` component category
3032
* ### My contribution includes a **new instrument** file
3133
* [ ] I have used the `mcdoc` utility and **rendered** a reasonable documentation page for the instrument (please attach as screenshot in comments!)

0 commit comments

Comments
 (0)