Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_tree():
assert len(tree) == len(pkgs)
assert all((isinstance(k, DistPackage) and
all(isinstance(v, ReqPackage) for v in vs))
for k, vs in tree.items())
def test_reverse_tree():
rtree = reverse_tree(tree)
assert all(isinstance(k, ReqPackage) for k, vs in rtree.items())
assert all(all(isinstance(v, DistPackage) for v in vs)
for k, vs in rtree.items())
assert all(all(v.req is not None for v in vs)
for k, vs in rtree.items())
def as_requirement(self):
"""Return a ReqPackage representation of this DistPackage"""
return ReqPackage(self._obj.as_requirement(), dist=self)
def get_required_package_version(package):
"""Returns required version for a package
:param package: package for which the required version is requested
:return: version string
"""
package_version = None
if isinstance(package, pipdeptree.ReqPackage):
package_version = package.version_spec
return package_version or VERSION_ANY
def construct_tree(index):
"""Construct tree representation of the pkgs from the index.
The keys of the dict representing the tree will be objects of type
DistPackage and the values will be list of ReqPackage objects.
:param dict index: dist index ie. index of pkgs by their keys
:returns: tree of pkgs and their dependencies
:rtype: dict
"""
return dict((p, [ReqPackage(r, index.get(r.key))
for r in p.requires()])
for p in index.values())
def __init__(self, obj, dist=None):
super(ReqPackage, self).__init__(obj)
self.dist = dist