def get_package_tree(ignore_list=None, include_only=None):
"""Returns dependency package tree
:param ignore_list: list of dependencies to exclude from tree
:param include_only: list of dependencies to include if
:return: dictionary of top level packages with their dependencies
"""
ignore_list = [i.lower() for i in ignore_list] if ignore_list else []
include_only = [i.lower() for i in include_only] if include_only else []
packages = [
package for package in
pip.get_installed_distributions()
if package.key not in ignore_list
]
# if include_only is set, remove other packages
if include_only:
packages = [
package for package in packages
if package.key in include_only
]
dist_index = pipdeptree.build_dist_index(pkgs=packages)
tree = pipdeptree.construct_tree(index=dist_index)
return tree
评论列表
文章目录