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_build_dist_index():
assert len(dist_index) == len(pkgs)
assert all(isinstance(x, str) for x in dist_index.keys())
assert all(isinstance(x, DistPackage) for x in dist_index.values())
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 __init__(self, obj, req=None):
super(DistPackage, self).__init__(obj)
self.version_spec = None
self.req = req
def build_dist_index(pkgs):
"""Build an index pkgs by their key as a dict.
:param list pkgs: list of pkg_resources.Distribution instances
:returns: index of the pkgs by the pkg key
:rtype: dict
"""
return dict((p.key, DistPackage(p)) for p in pkgs)
def get_installed_package_version(package):
"""Returns installed package version
:param package: package for which the version is requested
:return: version string
"""
package_version = None
if isinstance(package, pipdeptree.ReqPackage):
return package.installed_version
elif isinstance(package, pipdeptree.DistPackage):
package_version = package.version
return package_version or VERSION_ANY