diff options
author | Angus Gratton <angus@redyak.com.au> | 2022-08-29 17:30:14 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2022-10-04 14:52:48 +1100 |
commit | 0e35c4de9b9d55f9288eeb908efd2f7f577dc13b (patch) | |
tree | 8e5ddd70fb8d692ab88b07af431f1b0a3d53c8e8 /tools/codeformat.py | |
parent | bdac8272d8b1a726012bec897dc51dacbe70b295 (diff) |
tools: Add pre-commit support.
Tweak the existing codeformat.py and verifygitlog.py to allow them to be
easily called by pre-commit.
(This turned out to be easier than using any existing pre-commit hooks,
without making subtle changes in the formatting.)
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Diffstat (limited to 'tools/codeformat.py')
-rwxr-xr-x | tools/codeformat.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tools/codeformat.py b/tools/codeformat.py index 1c865663a..13a699065 100755 --- a/tools/codeformat.py +++ b/tools/codeformat.py @@ -151,6 +151,11 @@ def main(): cmd_parser.add_argument("-c", action="store_true", help="Format C code only") cmd_parser.add_argument("-p", action="store_true", help="Format Python code only") cmd_parser.add_argument("-v", action="store_true", help="Enable verbose output") + cmd_parser.add_argument( + "-f", + action="store_true", + help="Filter files provided on the command line against the default list of files to check.", + ) cmd_parser.add_argument("files", nargs="*", help="Run on specific globs") args = cmd_parser.parse_args() @@ -162,6 +167,16 @@ def main(): files = [] if args.files: files = list_files(args.files) + if args.f: + # Filter against the default list of files. This is a little fiddly + # because we need to apply both the inclusion globs given in PATHS + # as well as the EXCLUSIONS, and use absolute paths + files = set(os.path.abspath(f) for f in files) + all_files = set(list_files(PATHS, EXCLUSIONS, TOP)) + if args.v: # In verbose mode, log any files we're skipping + for f in files - all_files: + print("Not checking: {}".format(f)) + files = list(files & all_files) else: files = list_files(PATHS, EXCLUSIONS, TOP) |