# eric7.PipInterface.pipdeptree

Copyright (c) 2015 Vineet Naik (naikvin@gmail.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

### Global Attributes

__version__
flatten

### Classes

DistPackage | Wrapper class for pkg_resources.Distribution instances
Package | Abstract class for wrappers around objects that pip returns.
PackageDAG | Representation of Package dependencies as directed acyclic graph using a dict (Mapping) as the underlying datastructure.
ReqPackage | Wrapper class for Requirements instance
ReversedPackageDAG | Representation of Package dependencies in the reverse order.

### Functions

_get_args |
aux |
aux |
conflicting_deps | Returns dependencies which are not present or conflict with the requirements of other packages.
cyclic_deps | Return cyclic dependencies as list of tuples
dump_graphviz | Output dependency graph as one of the supported GraphViz output formats.
frozen_req_from_dist |
get_installed_distributions |
get_parser |
guess_version | Guess the version of a pkg when pip doesn't provide it
handle_non_host_target |
main |
print_graphviz | Dump the data generated by GraphViz to stdout.
render_conflicts_text |
render_cycles_text |
render_json | Converts the tree into a flat json representation.
render_json_tree | Converts the tree into a nested json representation.
render_text | Print tree as text on console
sorted_tree | Sorts the dict representation of the tree

## DistPackage

Wrapper class for pkg_resources.Distribution instances

:param obj: pkg_resources.Distribution to wrap over :param req: optional ReqPackage object to associate this DistPackage with. This is useful for displaying the tree in reverse

### Derived from

Package

### Class Attributes

None

### Class Methods

None

### Methods

DistPackage |
as_dict |
as_parent_of | Return a DistPackage instance associated to a requirement
as_requirement | Return a ReqPackage representation of this DistPackage
render_as_branch |
render_as_root |

### Static Methods

None

#### DistPackage (Constructor)

DistPackage(obj, req=None)

#### DistPackage.as_dict

as_dict()

#### DistPackage.as_parent_of

as_parent_of(req)

Return a DistPackage instance associated to a requirement

This association is necessary for reversing the PackageDAG.

If `req` is None, and the `req` attribute of the current instance is also None, then the same instance will be returned.

:param ReqPackage req: the requirement to associate with :returns: DistPackage instance

#### DistPackage.as_requirement

as_requirement()

Return a ReqPackage representation of this DistPackage

#### DistPackage.render_as_branch

render_as_branch(frozen)

#### DistPackage.render_as_root

render_as_root(frozen)
Up

## Package

Abstract class for wrappers around objects that pip returns.

This class needs to be subclassed with implementations for `render_as_root` and `render_as_branch` methods.

### Derived from

object

### Class Attributes

None

### Class Methods

None

### Methods

Package |
__getattr__ |
__lt__ |
__repr__ |
render |
render_as_branch |
render_as_root |

### Static Methods

frozen_repr |

#### Package (Constructor)

Package(obj)

#### Package.__getattr__

__getattr__(key)

#### Package.__lt__

__lt__(rhs)

#### Package.__repr__

__repr__()

#### Package.render

render(parent=None, frozen=False)

#### Package.render_as_branch

render_as_branch(frozen)

#### Package.render_as_root

render_as_root(frozen)

#### Package.frozen_repr (static)

frozen_repr()
Up

## PackageDAG

Representation of Package dependencies as directed acyclic graph using a dict (Mapping) as the underlying datastructure.

The nodes and their relationships (edges) are internally stored using a map as follows,

{a: [b, c], b: [d], c: [d, e], d: [e], e: [], f: [b], g: [e, f]}

Here, node `a` has 2 children nodes `b` and `c`. Consider edge direction from `a` -> `b` and `a` -> `c` respectively.

A node is expected to be an instance of a subclass of `Package`. The keys are must be of class `DistPackage` and each item in values must be of class `ReqPackage`. (See also ReversedPackageDAG where the key and value types are interchanged).

### Derived from

Mapping

### Class Attributes

None

### Class Methods

from_pkgs |

### Methods

PackageDAG | Initialize the PackageDAG object
__getitem__ |
__iter__ |
__len__ |
filter | Filters nodes in a graph by given parameters
get_children | Get child nodes for a node by it's key
get_node_as_parent | Get the node from the keys of the dict representing the DAG.
reverse | Reverse the DAG, or turn it upside-down
sort | Return sorted tree in which the underlying _obj dict is an OrderedDict, sorted alphabetically by the keys

### Static Methods

None

#### PackageDAG.from_pkgs (class method)

from_pkgs(pkgs)

#### PackageDAG (Constructor)

PackageDAG(m)

Initialize the PackageDAG object

:param dict m: dict of node objects (refer class docstring) :returns: None :rtype: NoneType

#### PackageDAG.__getitem__

__getitem__(*args)

#### PackageDAG.__iter__

__iter__()

#### PackageDAG.__len__

__len__()

#### PackageDAG.filter

filter(include, exclude)

Filters nodes in a graph by given parameters

If a node is included, then all it's children are also included.

:param set include: set of node keys to include (or None) :param set exclude: set of node keys to exclude (or None) :returns: filtered version of the graph :rtype: PackageDAG

#### PackageDAG.get_children

get_children(node_key)

Get child nodes for a node by it's key

:param str node_key: key of the node to get children of :returns: list of child nodes :rtype: ReqPackage[]

#### PackageDAG.get_node_as_parent

get_node_as_parent(node_key)

Get the node from the keys of the dict representing the DAG.

This method is useful if the dict representing the DAG contains different kind of objects in keys and values. Use this method to lookup a node obj as a parent (from the keys of the dict) given a node key.

:param node_key: identifier corresponding to key attr of node obj :returns: node obj (as present in the keys of the dict) :rtype: Object

#### PackageDAG.reverse

reverse()

Reverse the DAG, or turn it upside-down

In other words, the directions of edges of the nodes in the DAG will be reversed.

Note that this function purely works on the nodes in the graph. This implies that to perform a combination of filtering and reversing, the order in which `filter` and `reverse` methods should be applied is important. For eg. if reverse is called on a filtered graph, then only the filtered nodes and it's children will be considered when reversing. On the other hand, if filter is called on reversed DAG, then the definition of "child" nodes is as per the reversed DAG.

:returns: DAG in the reversed form :rtype: ReversedPackageDAG

#### PackageDAG.sort

sort()

Return sorted tree in which the underlying _obj dict is an OrderedDict, sorted alphabetically by the keys

:returns: Instance of same class with OrderedDict

Up

## ReqPackage

Wrapper class for Requirements instance

:param obj: The `Requirements` instance to wrap over :param dist: optional `pkg_resources.Distribution` instance for this requirement

### Derived from

Package

### Class Attributes

UNKNOWN_VERSION

### Class Methods

None

### Methods

ReqPackage |
as_dict |
installed_version |
is_conflicting | If installed version conflicts with required version
is_missing |
render_as_branch |
render_as_root |
version_spec |

### Static Methods

None

#### ReqPackage (Constructor)

ReqPackage(obj, dist=None)

#### ReqPackage.as_dict

as_dict()

#### ReqPackage.installed_version

installed_version()

#### ReqPackage.is_conflicting

is_conflicting()

If installed version conflicts with required version

#### ReqPackage.is_missing

is_missing()

#### ReqPackage.render_as_branch

render_as_branch(frozen)

#### ReqPackage.render_as_root

render_as_root(frozen)

#### ReqPackage.version_spec

version_spec()
Up

## ReversedPackageDAG

Representation of Package dependencies in the reverse order.

Similar to it's super class `PackageDAG`, the underlying datastructure is a dict, but here the keys are expected to be of type `ReqPackage` and each item in the values of type `DistPackage`.

Typically, this object will be obtained by calling `PackageDAG.reverse`.

### Derived from

PackageDAG

### Class Attributes

None

### Class Methods

None

### Methods

reverse | Reverse the already reversed DAG to get the PackageDAG again

### Static Methods

None

#### ReversedPackageDAG.reverse

reverse()

Reverse the already reversed DAG to get the PackageDAG again

:returns: reverse of the reversed DAG :rtype: PackageDAG

Up

## _get_args

_get_args()
Up

## aux

aux(node, parent=None, indent=0, chain=None)
Up

## aux

aux(node, parent=None, chain=None)
Up

## conflicting_deps

conflicting_deps(tree)

Returns dependencies which are not present or conflict with the requirements of other packages.

e.g. will warn if pkg1 requires pkg2==2.0 and pkg2==1.0 is installed

:param tree: the requirements tree (dict) :returns: dict of DistPackage -> list of unsatisfied/unknown ReqPackage :rtype: dict

Up

## cyclic_deps

cyclic_deps(tree)

Return cyclic dependencies as list of tuples

:param PackageDAG pkgs: package tree/dag :returns: list of tuples representing cyclic dependencies :rtype: list

Up

## dump_graphviz

dump_graphviz(tree, output_format='dot', is_reverse=False)

Output dependency graph as one of the supported GraphViz output formats.

:param dict tree: dependency graph :param string output_format: output format :returns: representation of tree in the specified output format :rtype: str or binary representation depending on the output format

Up

## frozen_req_from_dist

frozen_req_from_dist(dist)
Up

## get_installed_distributions

get_installed_distributions(local_only=False, user_only=False)
Up

## get_parser

get_parser()
Up

## guess_version

guess_version(pkg_key, default='?')

Guess the version of a pkg when pip doesn't provide it

:param str pkg_key: key of the package :param str default: default version to return if unable to find :returns: version :rtype: string

Up

## handle_non_host_target

handle_non_host_target(args)
Up

## main

main()
Up

## print_graphviz

print_graphviz(dump_output)

Dump the data generated by GraphViz to stdout.

:param dump_output: The output from dump_graphviz

Up

## render_conflicts_text

render_conflicts_text(conflicts)
Up

## render_cycles_text

render_cycles_text(cycles)
Up

## render_json

render_json(tree, indent)

Converts the tree into a flat json representation.

The json repr will be a list of hashes, each hash having 2 fields: - package - dependencies: list of dependencies

:param dict tree: dependency tree :param int indent: no. of spaces to indent json :returns: json representation of the tree :rtype: str

Up

## render_json_tree

render_json_tree(tree, indent)

Converts the tree into a nested json representation.

The json repr will be a list of hashes, each hash having the following fields: - package_name - key - required_version - installed_version - dependencies: list of dependencies

:param dict tree: dependency tree :param int indent: no. of spaces to indent json :returns: json representation of the tree :rtype: str

Up

## render_text

render_text(tree, list_all=True, frozen=False)

Print tree as text on console

:param dict tree: the package tree :param bool list_all: whether to list all the pgks at the root level or only those that are the sub-dependencies :param bool frozen: whether or not show the names of the pkgs in the output that's favourable to pip --freeze :returns: None

Up

## sorted_tree

sorted_tree(tree)

Sorts the dict representation of the tree

The root packages as well as the intermediate packages are sorted in the alphabetical order of the package names.

:param dict tree: the pkg dependency tree obtained by calling `construct_tree` function :returns: sorted tree :rtype: collections.OrderedDict

Up