mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-28 21:31:26 -07:00
module_utils fixes in collections (#55118)
* module_utils fixes in collections * fixed Windows module_utils in collections * fixed more Python module_utils cases (from X import module) * "medium style" Ansiballz modules now work properly with collections (ie, non-replacer but also not using basic.py) * added more tests * split Windows/POSIX exec * sanity
This commit is contained in:
parent
9bd060292e
commit
1dc8436ed9
25 changed files with 226 additions and 32 deletions
|
@ -473,7 +473,15 @@ class ModuleDepFinder(ast.NodeVisitor):
|
|||
|
||||
elif node.module.startswith('ansible_collections.'):
|
||||
# TODO: finish out the subpackage et al cases
|
||||
self.submodules.add(tuple(node.module.split('.')))
|
||||
if node.module.endswith('plugins.module_utils'):
|
||||
# from ansible_collections.ns.coll.plugins.module_utils import MODULE [as aname] [,MODULE2] [as aname]
|
||||
py_mod = tuple(node.module.split('.'))
|
||||
for alias in node.names:
|
||||
self.submodules.add(py_mod + (alias.name,))
|
||||
else:
|
||||
# from ansible_collections.ns.coll.plugins.module_utils.MODULE import IDENTIFIER [as aname]
|
||||
self.submodules.add(tuple(node.module.split('.')))
|
||||
|
||||
self.generic_visit(node)
|
||||
|
||||
|
||||
|
@ -762,7 +770,9 @@ def _find_module_utils(module_name, b_module_data, module_path, module_args, tas
|
|||
module_style = 'new'
|
||||
module_substyle = 'python'
|
||||
b_module_data = b_module_data.replace(REPLACER, b'from ansible.module_utils.basic import *')
|
||||
elif b'from ansible.module_utils.' in b_module_data:
|
||||
# FUTURE: combined regex for this stuff, or a "looks like Python, let's inspect further" mechanism
|
||||
elif b'from ansible.module_utils.' in b_module_data or b'from ansible_collections.' in b_module_data\
|
||||
or b'import ansible_collections.' in b_module_data:
|
||||
module_style = 'new'
|
||||
module_substyle = 'python'
|
||||
elif REPLACER_WINDOWS in b_module_data:
|
||||
|
@ -772,6 +782,7 @@ def _find_module_utils(module_name, b_module_data, module_path, module_args, tas
|
|||
elif re.search(b'#Requires -Module', b_module_data, re.IGNORECASE) \
|
||||
or re.search(b'#Requires -Version', b_module_data, re.IGNORECASE)\
|
||||
or re.search(b'#AnsibleRequires -OSVersion', b_module_data, re.IGNORECASE) \
|
||||
or re.search(b'#AnsibleRequires -Powershell', b_module_data, re.IGNORECASE) \
|
||||
or re.search(b'#AnsibleRequires -CSharpUtil', b_module_data, re.IGNORECASE):
|
||||
module_style = 'new'
|
||||
module_substyle = 'powershell'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue