mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-28 21:31:26 -07:00
Overhaul ansible-test import analysis. (#22888)
- Add support for module_utils packages for better organization. - Add support for "virtual" module_utils packages such as `six`.
This commit is contained in:
parent
ac992eff1c
commit
4fdeade389
2 changed files with 110 additions and 27 deletions
|
@ -130,19 +130,22 @@ class PathMapper(object):
|
|||
:type path: str
|
||||
:rtype: list[str]
|
||||
"""
|
||||
name, ext = os.path.splitext(os.path.split(path)[1])
|
||||
ext = os.path.splitext(os.path.split(path)[1])[1]
|
||||
|
||||
if path.startswith('lib/ansible/module_utils/'):
|
||||
if ext == '.py':
|
||||
return self.get_python_module_utils_usage(name)
|
||||
return self.get_python_module_utils_usage(path)
|
||||
|
||||
return []
|
||||
|
||||
def get_python_module_utils_usage(self, name):
|
||||
def get_python_module_utils_usage(self, path):
|
||||
"""
|
||||
:type name: str
|
||||
:type path: str
|
||||
:rtype: list[str]
|
||||
"""
|
||||
if path == 'lib/ansible/module_utils/__init__.py':
|
||||
return []
|
||||
|
||||
if not self.python_module_utils_imports:
|
||||
display.info('Analyzing python module_utils imports...')
|
||||
before = time.time()
|
||||
|
@ -150,7 +153,12 @@ class PathMapper(object):
|
|||
after = time.time()
|
||||
display.info('Processed %d python module_utils in %d second(s).' % (len(self.python_module_utils_imports), after - before))
|
||||
|
||||
return sorted(self.python_module_utils_imports.get(name, set()))
|
||||
name = os.path.splitext(path)[0].replace('/', '.')[4:]
|
||||
|
||||
if name.endswith('.__init__'):
|
||||
name = name[:-9]
|
||||
|
||||
return sorted(self.python_module_utils_imports[name])
|
||||
|
||||
def classify(self, path):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue