Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def venv_fixture(pickle_file):
"""Loads required virtualenv pkg data from a pickle file
:param pickle_file: path to a .pickle file
:returns: a tuple of pkgs, pkg_index, req_map
:rtype: tuple
"""
with open(pickle_file, 'rb') as f:
pkgs = pickle.load(f)
dist_index = build_dist_index(pkgs)
tree = construct_tree(dist_index)
return pkgs, dist_index, tree
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
Args:
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: