From 3c02af64942d96241ec3effc08fd6b27a300bdc7 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Thu, 12 May 2016 11:24:28 -0500 Subject: [PATCH] BLACKLIST_IMPORTS can be regex to making matching easier --- ansible_testing/modules.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/ansible_testing/modules.py b/ansible_testing/modules.py index f56e83c2dc4..4833569e323 100644 --- a/ansible_testing/modules.py +++ b/ansible_testing/modules.py @@ -51,7 +51,7 @@ BLACKLIST_IMPORTS = { 'msg': ('requests import found, should use ' 'ansible.module_utils.urls instead') }, - 'boto': { + 'boto(?:\.|$)': { 'new_only': True, 'msg': ('boto import found, new modules should use boto3') }, @@ -216,13 +216,14 @@ class ModuleValidator(Validator): if isinstance(grandchild, ast.Import): names.extend(grandchild.names) for name in names: - if name.name in BLACKLIST_IMPORTS: - msg = BLACKLIST_IMPORTS[name.name]['msg'] - new_only = BLACKLIST_IMPORTS[name.name]['new_only'] - if self._is_new_module() and new_only: - self.errors.append(msg) - elif not new_only: - self.errors.append(msg) + for blacklist_import, options in BLACKLIST_IMPORTS.items(): + if re.search(blacklist_import, name.name): + msg = options['msg'] + new_only = options['new_only'] + if self._is_new_module() and new_only: + self.errors.append(msg) + elif not new_only: + self.errors.append(msg) def _find_module_utils(self, main):