You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
652 B

5 years ago
  1. # -*- coding: utf-8 -*-
  2. import collections
  3. from .core import Check
  4. custom_checks_per_module = collections.defaultdict(list)
  5. class CustomCheck(Check):
  6. def __init__(self, module, func):
  7. super(CustomCheck, self).__init__(module)
  8. self.func = func
  9. def _run(self, env):
  10. return self.func(env)
  11. def custom_check(func):
  12. try:
  13. module = func.__module__.split('.')[2]
  14. except IndexError:
  15. module = ''
  16. custom_checks_per_module[module].append(
  17. CustomCheck(module=module, func=func)
  18. )
  19. return func
  20. def get_checks_for_module(module_name):
  21. return custom_checks_per_module[module_name]