1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

BLACKLIST_IMPORTS can be regex to making matching easier

This commit is contained in:
Matt Martz 2016-05-12 11:24:28 -05:00 committed by John Barker
parent 44fa8c1fb2
commit 3c02af6494

View file

@ -51,7 +51,7 @@ BLACKLIST_IMPORTS = {
'msg': ('requests import found, should use ' 'msg': ('requests import found, should use '
'ansible.module_utils.urls instead') 'ansible.module_utils.urls instead')
}, },
'boto': { 'boto(?:\.|$)': {
'new_only': True, 'new_only': True,
'msg': ('boto import found, new modules should use boto3') 'msg': ('boto import found, new modules should use boto3')
}, },
@ -216,13 +216,14 @@ class ModuleValidator(Validator):
if isinstance(grandchild, ast.Import): if isinstance(grandchild, ast.Import):
names.extend(grandchild.names) names.extend(grandchild.names)
for name in names: for name in names:
if name.name in BLACKLIST_IMPORTS: for blacklist_import, options in BLACKLIST_IMPORTS.items():
msg = BLACKLIST_IMPORTS[name.name]['msg'] if re.search(blacklist_import, name.name):
new_only = BLACKLIST_IMPORTS[name.name]['new_only'] msg = options['msg']
if self._is_new_module() and new_only: new_only = options['new_only']
self.errors.append(msg) if self._is_new_module() and new_only:
elif not new_only: self.errors.append(msg)
self.errors.append(msg) elif not new_only:
self.errors.append(msg)
def _find_module_utils(self, main): def _find_module_utils(self, main):