autotest_unused: Ignore a few more filepaths A few filepaths really need to be ignored when grepping: * BeautifulSoup.py, a clone of an upstream repository * *_functional_test.py, a suffix used for testing code This CL always ignores BeautifulSoup, ignores _functional_test.py when ignoring unittests, and sets up a reusable framework for ignoring other globs in the future. BUG=None TEST=autotest_unused.py -d site_utils Change-Id: I1bd36863acd1f2d1767348c82ca6b77649b7d6f1 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crostestutils/+/2519198 Tested-by: Greg Edelston <gredelston@google.com> Auto-Submit: Greg Edelston <gredelston@google.com> Reviewed-by: Derek Beckett <dbeckett@chromium.org> Reviewed-by: Kevin Shelton <kmshelton@chromium.org> Commit-Queue: Greg Edelston <gredelston@google.com>
diff --git a/code_health/autotest_unused.py b/code_health/autotest_unused.py index fe920d2..b771f7b 100755 --- a/code_health/autotest_unused.py +++ b/code_health/autotest_unused.py
@@ -24,6 +24,7 @@ """ import argparse +import copy import logging import os import re @@ -45,6 +46,19 @@ ] +# Unix-style globs to always ignore when grepping. +ALWAYS_IGNORE_GLOBS = [ + '**/server/cros/faft/fw-testing-configs/**', + '**/site_utils/rpm_control_system/BeautifulSoup.py', +] + +# Unix-style globs of unittest paths to sometimes ignore when grepping. +UNITTEST_GLOBS = [ + '**_unittest.py', + '**_functional_test.py' +] + + def require_chroot(): """Exit with status 2 if not in the chroot.""" if not os.path.isfile('/etc/cros_chroot_version'): @@ -107,13 +121,13 @@ '--no-line-number', # Require word-boundaries. '-w', - # Always exclude fw-testing-configs/. - '--iglob', - '\'!**/server/cros/faft/fw-testing-configs/**\'', ] + ignore_globs = copy.copy(ALWAYS_IGNORE_GLOBS) if exclude_unittests: - flags += ['--iglob', '\'!*_unittest.py\''] - cmd = 'rg %s \'%s\' %s' % (' '.join(flags), pattern, ' '.join(paths)) + ignore_globs.extend(UNITTEST_GLOBS) + for glob in ignore_globs: + flags.extend(['--iglob', "'!%s'" % glob]) + cmd = "rg %s '%s' %s" % (' '.join(flags), pattern, ' '.join(paths)) proc = subprocess.run(cmd, stdout=subprocess.PIPE, universal_newlines=True,