Welcome to py_deps’s documentation!

Contents:

About py-dep

The py-dep provides parsing the dependencies of Python packages and generating the metadata for graph.

The graph data is for NetworkX, Graphviz, blockdiag, Linkdraw, etc.

Status

https://secure.travis-ci.org/mkouhei/py-deps.png?branch=master https://coveralls.io/repos/mkouhei/py-deps/badge.png?branch=master Documentation Status

Requirements

  • Python 2.7 over or Python 3.3 over or PyPy 2.4.0 over
  • pip 1.5.6 or 6.1.1 over
  • wheel 0.24.0 over
  • NetworkX 1.9 over

Features

  • Generating Linkdraw data.
  • Generating Networkx DiGraph object data.
  • Cache the parsed dependencies.

Basic usage

py-deps provides parsing the Python deps and generating graph data.

Initialize

Cache the parsed dependencies into the py-deps.pickle on current working directory.This file format is pickle.:

$ python
>>> from py_deps import Package
>>> pkg = Package('py-deps')

Change cache file

Use cache_name argument.:

>>> pkg = Package('py-deps', cache_name='some-cache.name')

Override cache forcely

Use update_force argument. (default: False):

>>> pkg = Package('py-deps', update_force=True)

Generate rendering data

Supports follows currently.

  • pretty print
  • Linkdraw

Pretty print

>>> print(pkg.draw())
py-deps -> [Sphinx, setuptools, pip, wheel, tox]
setuptools -> [certifi, wincertstore, setuptools[ssl], pytest]
pip -> [pytest, virtualenv, scripttest, mock, pytest, virtualenv,
 scripttest, mock]
wheel -> [ed25519ll, keyring, argparse, pyxdg, jsonschema, pytest,
 coverage, pytest-cov]
>>>

Linkdraw

>>> import json
>>> json.loads(pkg.draw('linkdraw'))
{u'descr': u'py-deps dependencies',
 u'lines': [{u'color': u'#5F9EA0', u'descr': u'\u2192', u'link': u'',
   u'source': u'py-deps', u'target': u'Sphinx', u'width': u'1'},
  {u'color': u'#5F9EA0', u'descr': u'\u2192', u'link': u'',
   u'source': u'py-deps', u'target': u'setuptools', u'width': u'1'},
  {u'color': u'#5F9EA0', u'descr': u'\u2192', u'link': u'',
   u'source': u'py-deps', u'target': u'pip', u'width': u'1'},
  {u'color': u'#5F9EA0', u'descr': u'\u2192', u'link': u'',
   u'source': u'py-deps', u'target': u'wheel', u'width': u'1'},
  {u'color': u'#5F9EA0', u'descr': u'\u2192', u'link': u'',
   u'source': u'py-deps', u'target': u'tox', u'width': u'1'},
  {u'color': u'#5F9EA0', u'descr': u'\u2192', u'link': u'',
   u'source': u'setuptools', u'target': u'certifi', u'width': u'1'},
  {u'color': u'#5F9EA0', u'descr': u'\u2192', u'link': u'',
   u'source': u'setuptools', u'target': u'wincertstore', u'width': u'1'},
  {u'color': u'#5F9EA0', u'descr': u'\u2192', u'link': u'',
   u'source': u'setuptools', u'target': u'setuptools____ssl',
   u'width': u'1'},
  {u'color': u'#5F9EA0', u'descr': u'\u2192', u'link': u'',
   u'source': u'setuptools', u'target': u'pytest', u'width': u'1'},
  {u'color': u'#5F9EA0', u'descr': u'\u2192', u'link': u'',
   u'source': u'pip', u'target': u'pytest', u'width': u'1'},
  {u'color': u'#5F9EA0', u'descr': u'\u2192', u'link': u'',
   u'source': u'pip', u'target': u'virtualenv', u'width': u'1'},
  {u'color': u'#5F9EA0', u'descr': u'\u2192', u'link': u'',
   u'source': u'pip', u'target': u'scripttest', u'width': u'1'},
  {u'color': u'#5F9EA0', u'descr': u'\u2192', u'link': u'',
   u'source': u'pip', u'target': u'mock', u'width': u'1'},
  {u'color': u'#5F9EA0', u'descr': u'\u2192', u'link': u'',
   u'source': u'pip', u'target': u'pytest', u'width': u'1'},
  {u'color': u'#5F9EA0', u'descr': u'\u2192', u'link': u'',
   u'source': u'pip', u'target': u'virtualenv', u'width': u'1'},
  {u'color': u'#5F9EA0', u'descr': u'\u2192', u'link': u'',
   u'source': u'pip', u'target': u'scripttest', u'width': u'1'},
  {u'color': u'#5F9EA0', u'descr': u'\u2192', u'link': u'',
   u'source': u'pip', u'target': u'mock', u'width': u'1'},
  {u'color': u'#5F9EA0', u'descr': u'\u2192', u'link': u'',
   u'source': u'wheel', u'target': u'ed25519ll', u'width': u'1'},
  {u'color': u'#5F9EA0', u'descr': u'\u2192', u'link': u'',
   u'source': u'wheel', u'target': u'keyring', u'width': u'1'},
  {u'color': u'#5F9EA0', u'descr': u'\u2192', u'link': u'',
   u'source': u'wheel', u'target': u'argparse', u'width': u'1'},
  {u'color': u'#5F9EA0', u'descr': u'\u2192', u'link': u'',
   u'source': u'wheel', u'target': u'pyxdg', u'width': u'1'},
  {u'color': u'#5F9EA0', u'descr': u'\u2192', u'link': u'',
   u'source': u'wheel', u'target': u'jsonschema', u'width': u'1'},
  {u'color': u'#5F9EA0', u'descr': u'\u2192', u'link': u'',
   u'source': u'wheel', u'target': u'pytest', u'width': u'1'},
  {u'color': u'#5F9EA0', u'descr': u'\u2192', u'link': u'',
   u'source': u'wheel', u'target': u'coverage', u'width': u'1'},
  {u'color': u'#5F9EA0', u'descr': u'\u2192', u'link': u'',
   u'source': u'wheel', u'target': u'pytest-cov', u'width': u'1'}],
 u'nodes': [{u'color': u'', u'link': u'https://github.com/mkouhei/py-deps',
   u'name': u'py-deps', u'r': u'6'},
  {u'color': u'#5F9EA0', u'link': u'', u'name': u'Sphinx', u'r': u'6'},
  {u'color': u'#5F9EA0', u'link': u'https://bitbucket.org/pypa/setuptools',
   u'name': u'setuptools', u'r': u'6'},
  {u'color': u'#5F9EA0', u'link': u'https://pip.pypa.io/',
   u'name': u'pip', u'r': u'6'},
  {u'color': u'#5F9EA0', u'link': u'http://bitbucket.org/pypa/wheel/',
   u'name': u'wheel', u'r': u'6'},
  {u'color': u'#5F9EA0', u'link': u'', u'name': u'tox', u'r': u'6'},
  {u'color': u'#5F9EA0', u'link': u'', u'name': u'certifi', u'r': u'6'},
  {u'color': u'#5F9EA0', u'link': u'', u'name': u'wincertstore',
   u'r': u'6'},
  {u'color': u'#5F9EA0', u'link': u'', u'name': u'setuptools____ssl',
   u'r': u'6'},
  {u'color': u'#5F9EA0', u'link': u'', u'name': u'pytest', u'r': u'6'},
  {u'color': u'#5F9EA0', u'link': u'', u'name': u'virtualenv', u'r': u'6'},
  {u'color': u'#5F9EA0', u'link': u'', u'name': u'scripttest', u'r': u'6'},
  {u'color': u'#5F9EA0', u'link': u'', u'name': u'mock', u'r': u'6'},
  {u'color': u'#5F9EA0', u'link': u'', u'name': u'ed25519ll', u'r': u'6'},
  {u'color': u'#5F9EA0', u'link': u'', u'name': u'keyring', u'r': u'6'},
  {u'color': u'#5F9EA0', u'link': u'', u'name': u'argparse', u'r': u'6'},
  {u'color': u'#5F9EA0', u'link': u'', u'name': u'pyxdg', u'r': u'6'},
  {u'color': u'#5F9EA0', u'link': u'', u'name': u'jsonschema', u'r': u'6'},
  {u'color': u'#5F9EA0', u'link': u'', u'name': u'coverage', u'r': u'6'},
  {u'color': u'#5F9EA0', u'link': u'', u'name': u'pytest-cov',
   u'r': u'6'}],
 u'time': u'2015-05-08T03:52:59.542732'}

References

py_deps.deps module.

class py_deps.deps.Container(cache_name=None)

Bases: object

Package container class.

load_cache()

Load cache file.

read_data(key)

Read traced_chain data.

Return type:list
Returns:dependency chain list
Parameters:key (str) – package name
save_cache()

Save cache file.

store_data(key, data)

Store traced_chain data.

Parameters:
  • key (str) – package name
  • data (list) – traced dependency chain data
class py_deps.deps.Node(name, version=None, url=None)

Bases: object

Node object class.

add_targets(nodes)

Add targets.

add_test_targets(nodes)

Add test targets.

remove_targets(*nodes)

Remove targets.

class py_deps.deps.Package(name, cache_name=None, update_force=False)

Bases: object

Package class.

cleanup(alldir=False)

Cleanup temporary build directory.

Parameters:alldir (bool) – Remove all temporary directories. (default: False)
Return type:None
draw(draw_type=None)

Generate drawing data.

Parameters:draw_type (str) – [dot|blockdiag|linkdraw]
trace_chain(pkg_name=None)

Trace dependency chain.

Parameters:pkg_name (str) – package name
class py_deps.deps.Target(nodename, specs, extras=False)

Bases: py_deps.deps.Node

Target objects.

add_targets(nodes)

Add targets.

add_test_targets(nodes)

Add test targets.

remove_targets(*nodes)

Remove targets.

py_deps.graph module.

class py_deps.graph.Graph(chain_data)

Bases: object

Graph data generate abstract class.

generate_nodes()

Generate nodes data.

class py_deps.graph.Linkdraw(chain_data)

Bases: py_deps.graph.Graph

Linkdraw object class.

generate_data()

Generate Linkdraw data.

generate_edges()

Generate edges data.

generate_nodes()

Generate nodes data.

class py_deps.graph.Metadata

Bases: object

Metadata object class.

class py_deps.graph.Networkx(chain_data)

Bases: py_deps.graph.Graph

Networkx object class.

generate_data()

Generate networkx graph data.

generate_edges()

Generate edges data.

generate_nodes()

Generate nodes data.

py_deps.graph.pretty_print(chain_data)

Pretty print on terminal.

Parameters:chain_data (list) – List of deps.Node
py_deps.graph.router(chain_data, draw_type=None)

Routing drawing tool.

Design notes

Memo

purpose setup.py Egg wheel (metadata.json)
requires install_requires requires.txt run_requires.requires
no PyPI dependency_links dependency_links.txt  
optional extras_require   extras
extra resource     run_requires.extra
test     test_requires.requires

History

0.3.0 (2015-05-12)

  • Supports NetworkX DiGraph objects.
  • Changes to use mock instead of pip.req.RequirementSet.prepare_files.
  • Coverage 98% over.

0.2.0 (2015-05-10)

  • Cache the parsed dependencies.
  • Fixes setting the url of node and targets.

0.1.1 (2015-05-08)

  • Fixes test data of pretty_print, linkdraw.

0.1.0 (2015-05-07)

  • Supports generating linkdraw data.
  • Supports pip 6.1.1 over.
  • Supports wheel format for distribution.
  • Adds unit tests.

0.0.1 (2015-04-29)

  • First release

Indices and tables