diff --git a/flake8.cfg b/flake8.cfg index a3e81f96bcb91d3bd0b95cc4d40b67256e426a0d..48317219e05e1aae97f51152532d591a89e4b08e 100644 --- a/flake8.cfg +++ b/flake8.cfg @@ -3,3 +3,4 @@ max-line-length = 80 max-complexity = 14 format = pylint ignore = F403,F405,F999 +exclude = thirdparty/ diff --git a/scripts/developer/git/git-clang-format b/scripts/developer/git/git-clang-format index 74fd451a847be8cbbff6873fe2251f4315de7758..e0557e503ac5501841b91cd75bbe90fb8e53193e 100755 --- a/scripts/developer/git/git-clang-format +++ b/scripts/developer/git/git-clang-format @@ -112,6 +112,8 @@ def main(): help='passed to clang-format'), p.add_argument('-v', '--verbose', action='count', default=0, help='print extra information') + p.add_argument('-x', '--exclude', + help='Regex to match for files to exclude from checking') # We gather all the remaining positional arguments into 'args' since we need # to use some heuristics to determine whether or not <commit> was present. # However, to print pretty messages, we make use of metavar and help. @@ -134,6 +136,7 @@ def main(): changed_lines = compute_diff_and_extract_lines(commits, files) if opts.verbose >= 1: ignored_files = set(changed_lines) + filter_by_exclude(changed_lines, opts.exclude) filter_by_extension(changed_lines, opts.extensions.lower().split(',')) if opts.verbose >= 1: ignored_files.difference_update(changed_lines) @@ -314,6 +317,16 @@ def extract_lines(patch_file): return matches +def filter_by_exclude(dictionary, exclude_re): + """Delete every key in `dictionary` that matches the exclusion regex. + + `exclude_re` must be a valid regex.""" + exre = re.compile(exclude_re) + for filename in dictionary.keys(): + if exre.match(filename): + del dictionary[filename] + + def filter_by_extension(dictionary, allowed_extensions): """Delete every key in `dictionary` that doesn't have an allowed extension. diff --git a/scripts/travis/run-format.sh b/scripts/travis/run-format.sh index 79f393f7a0185e333e39d6ab69d0dd74933e3e1f..ac203f2ced4a6ae0218e36d889658b43e8da6572 100755 --- a/scripts/travis/run-format.sh +++ b/scripts/travis/run-format.sh @@ -15,7 +15,7 @@ cd ${SOURCE_DIR} # Check C and C++ code with clang-format echo "Checking formatting for commit range: ${COMMIT_RANGE}" -DIFF="$(./scripts/developer/git/git-clang-format --diff ${COMMIT_RANGE})" +DIFF="$(./scripts/developer/git/git-clang-format -x '^thirdparty/' --diff ${COMMIT_RANGE})" if [ -n "${DIFF}" ] && [ "${DIFF}" != "no modified files to format" ] then echo "clang-format:"