Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
package_name: The name of the package for which to build a dependency tree.
local_only: Look in local distribution? Default: True.
Returns:
A Python list containing information about the dependencies for that package.
"""
## Dealing with pip 10.* api chagnes
## The solution is from:
## https://github.com/naiquevin/pipdeptree/blob/master/pipdeptree.py
try:
from pip._internal.utils.misc import get_installed_distributions
except ImportError:
from pip import get_installed_distributions
packages = get_installed_distributions(local_only=local_only)
dist_index = build_dist_index(packages)
tree = sorted_tree(construct_tree(dist_index))
nodes = tree.keys()
# filter by our desired package only
nodes = [p for p in nodes if p.key == package_name or p.project_name == package_name]
if len(nodes) == 0:
raise PackageNotFoundError(package_name)
if len(nodes) > 1:
raise MultiplePackagesFoundError(package_name)
key_tree = dict((k.key, v) for k, v in iteritems(tree))
deps = recursive_extract_dep_list(key_tree, package_name)
unique_deps = []
seen_deps = set()
for dep in deps:
if dep.key not in seen_deps:
unique_deps.append(dep.as_dict())