diff --git a/utils/check-package b/utils/check-package index a959fef079..5fb430902d 100755 --- a/utils/check-package +++ b/utils/check-package @@ -8,6 +8,7 @@ import re import six import sys +import checkpackagelib.base import checkpackagelib.lib_config import checkpackagelib.lib_hash import checkpackagelib.lib_mk @@ -87,9 +88,7 @@ def get_lib_from_filename(fname): return None -def is_a_check_function(m): - if not inspect.isclass(m): - return False +def common_inspect_rules(m): # do not call the base class if m.__name__.startswith("_"): return False @@ -100,6 +99,22 @@ def is_a_check_function(m): return True +def is_a_check_function(m): + if not inspect.isclass(m): + return False + if not issubclass(m, checkpackagelib.base._CheckFunction): + return False + return common_inspect_rules(m) + + +def is_external_tool(m): + if not inspect.isclass(m): + return False + if not issubclass(m, checkpackagelib.base._Tool): + return False + return common_inspect_rules(m) + + def print_warnings(warnings): # Avoid the need to use 'return []' at the end of every check function. if warnings is None: @@ -121,14 +136,16 @@ def check_file_using_lib(fname): if flags.verbose >= VERBOSE_LEVEL_TO_SHOW_IGNORED_FILES: print("{}: ignored".format(fname)) return nwarnings, nlines - classes = inspect.getmembers(lib, is_a_check_function) + internal_functions = inspect.getmembers(lib, is_a_check_function) + external_tools = inspect.getmembers(lib, is_external_tool) + all_checks = internal_functions + external_tools if flags.dry_run: - functions_to_run = [c[0] for c in classes] + functions_to_run = [c[0] for c in all_checks] print("{}: would run: {}".format(fname, functions_to_run)) return nwarnings, nlines - objects = [c[1](fname, flags.manual_url) for c in classes] + objects = [c[1](fname, flags.manual_url) for c in internal_functions] for cf in objects: nwarnings += print_warnings(cf.before()) @@ -148,6 +165,11 @@ def check_file_using_lib(fname): for cf in objects: nwarnings += print_warnings(cf.after()) + tools = [c[1](fname) for c in external_tools] + + for tool in tools: + nwarnings += print_warnings(tool.run()) + return nwarnings, nlines diff --git a/utils/checkpackagelib/base.py b/utils/checkpackagelib/base.py index 9544a64e5a..73da925a03 100644 --- a/utils/checkpackagelib/base.py +++ b/utils/checkpackagelib/base.py @@ -16,3 +16,11 @@ class _CheckFunction(object): def after(self): pass + + +class _Tool(object): + def __init__(self, filename): + self.filename = filename + + def run(self): + pass