Skip to content

Instantly share code, notes, and snippets.

@maxbrunet
Created August 11, 2018 21:34
Show Gist options
  • Save maxbrunet/397a94cee3267c4ee3d3d13162a042cc to your computer and use it in GitHub Desktop.
Save maxbrunet/397a94cee3267c4ee3d3d13162a042cc to your computer and use it in GitHub Desktop.
Find missing dependencies for Ansible plugins. Related to Homebrew/homebrew-core#28839
#!/usr/bin/env python
from distutils.sysconfig import get_python_lib
from glob import iglob
from modulefinder import ModuleFinder
EXCLUDED_DEPENDENCIES = [
# Standard libraries
'distutils',
'func',
'multiprocessing',
'ordereddict',
'os',
'selectors',
# Ansible libraries
'ansible',
'library',
# Already included in Homebrew formula
'jinja2',
'ncclient',
'winrm',
# Irrelevant on MacOS
'lxc',
'selinux',
]
# Exclude Jinja2 to avoid import errors
# https://github.com/pallets/jinja/issues/643
finder = ModuleFinder(excludes=['jinja2'])
dependencies = set()
for script in iglob('{}/ansible/plugins/*/*.py'.format(get_python_lib())):
finder.run_script(script)
for module, caller in finder.badmodules.items():
if '__main__' in caller:
dependencies.add(module.split('.')[0])
dependencies.difference_update(EXCLUDED_DEPENDENCIES)
print('\n'.join(sorted(dependencies)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment