mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-28 13:21:25 -07:00
Rework module_utils detection for zipmodule
This commit is contained in:
parent
38464b1fdc
commit
b8b3003b29
1 changed files with 18 additions and 17 deletions
|
@ -214,31 +214,32 @@ class ModuleValidator(Validator):
|
||||||
|
|
||||||
def _find_module_utils(self, main):
|
def _find_module_utils(self, main):
|
||||||
linenos = []
|
linenos = []
|
||||||
|
found_basic = False
|
||||||
for child in self.ast.body:
|
for child in self.ast.body:
|
||||||
found_module_utils_import = False
|
if isinstance(child, (ast.Import, ast.ImportFrom)):
|
||||||
if isinstance(child, ast.ImportFrom):
|
names = []
|
||||||
if child.module.startswith('ansible.module_utils.'):
|
try:
|
||||||
found_module_utils_import = True
|
names.append(child.module)
|
||||||
|
if child.module.endswith('.basic'):
|
||||||
|
found_basic = True
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
names.extend([n.name for n in child.names])
|
||||||
|
|
||||||
|
if [n for n in names if n.startswith('ansible.module_utils')]:
|
||||||
linenos.append(child.lineno)
|
linenos.append(child.lineno)
|
||||||
|
|
||||||
if not child.names:
|
|
||||||
self.errors.append('%s: not a "from" import"' %
|
|
||||||
child.module)
|
|
||||||
|
|
||||||
found_alias = False
|
|
||||||
for name in child.names:
|
for name in child.names:
|
||||||
if isinstance(name, ast.alias):
|
print(name.name)
|
||||||
found_alias = True
|
if (isinstance(name, ast.alias) and
|
||||||
if name.asname or name.name != '*':
|
name.name == 'basic'):
|
||||||
self.errors.append('%s: did not import "*"' %
|
found_basic = True
|
||||||
child.module)
|
|
||||||
|
|
||||||
if found_module_utils_import and not found_alias:
|
|
||||||
self.errors.append('%s: did not import "*"' % child.module)
|
|
||||||
|
|
||||||
if not linenos:
|
if not linenos:
|
||||||
self.errors.append('Did not find a module_utils import')
|
self.errors.append('Did not find a module_utils import')
|
||||||
|
elif not found_basic:
|
||||||
|
self.errors.append('Did not find "ansible.module_utils.basic" '
|
||||||
|
'import')
|
||||||
|
|
||||||
return linenos
|
return linenos
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue