Skip to main content

Display module dependencies

Project description

Documentation Status https://travis-ci.org/thebjorn/pydeps.svg https://coveralls.io/repos/github/thebjorn/pydeps/badge.svg?branch=master Code Health

Python module dependency visualization. This package installs the pydeps command, and normal usage will be to use it from the command line.

New in version 1.5.0: Python 3 support (thanks to @eight04 for the PR)

New in version 1.3.4: --externals will now include modules that haven’t been installed (what modulefinder calls badmodules).

New in version 1.2.8: A shortcut for finding the direct external dependencies of a package was added:

pydeps --externals mypackage

which will print a json formatted list of module names to the screen, e.g.:

(dev) go|c:\srv\lib\dk-tasklib> pydeps --externals dktasklib
[
    "dkfileutils"
]

which meaans that the dktasklib package only depends on the dkfileutils package.

This functionality is also available programatically:

import os
from pydeps.pydeps import externals
# the directory that contains setup.py (one level up from actual package):
os.chdir('package-directory')
print externals('mypackage')

New in version 1.2.5: The defaults are now sensible, such that:

pydeps mypackage

will likely do what you want. It is the same as pydeps --show --max-bacon=2 mypackage which means display the dependency graph in your browser, but limit it to two hops (which includes only the modules that your module imports – not continuing down the import chain). The old default behavior is available with pydeps --noshow --max-bacon=0 mypackage.

To install:

pip install pydeps

To create graphs you need to install Graphviz (make sure the dot command is on your path).

This is the result of running pydeps on itself (pydeps pydeps):

https://raw.githubusercontent.com/thebjorn/pydeps/master/docs/_static/pydeps.svg?sanitize=true

pydeps also contains an Erdős-like scoring function (a.k.a. Bacon number, from Six degrees of Kevin Bacon (http://en.wikipedia.org/wiki/Six_Degrees_of_Kevin_Bacon) that lets you filter out modules that are more than a given number of ‘hops’ away from the module you’re interested in. This is useful for finding the interface a module has to the rest of the world.

To find pydeps’ interface to the Python stdlib (less some very common modules).

pydeps pydeps --show --max-bacon 2 --pylib -x os re types _* enum
https://raw.githubusercontent.com/thebjorn/pydeps/master/docs/_static/pydeps-pylib.svg?sanitize=true

--max-bacon 2 (the default) gives the modules that are at most 2 hops away, and modules that belong together have similar colors. Compare that to the output with the --max-bacon=0 (infinite) filter:

https://raw.githubusercontent.com/thebjorn/pydeps/master/docs/_static/pydeps-pylib-all.svg?sanitize=true

All options can also be set in a .pydeps file using .ini file syntax (parsable by ConfigParser). Command line options override options in the .pydeps file in the current directory, which again overrides options in the user’s home directory (%USERPROFILE%\.pydeps on Windows and ${HOME}/.pydeps otherwise).

pydeps can detect and display cycles with the --show-cycles parameter. This will _only_ display the cycles, and for big libraries it is not a particularly fast operation. Given a folder with the following contents (this uses yaml to define a directory structure, like in the tests):

relimp:
    - __init__.py
    - a.py: |
        from . import b
    - b.py: |
        from . import a

pydeps relimp --show-cycles displays:

https://raw.githubusercontent.com/thebjorn/pydeps/master/docs/_static/pydeps-cycle.svg?sanitize=true

An attempt has been made to keep the intermediate formats readable, eg. the output from pydeps --show-deps .. looks like this:

...
"pydeps.mf27": {
    "imported_by": [
        "__main__",
        "pydeps.py2depgraph"
    ],
    "kind": "imp.PY_SOURCE",
    "name": "pydeps.mf27",
    "path": "pydeps\\mf27.py"
},
"pydeps.py2depgraph": {
    "imported_by": [
        "__main__",
        "pydeps.pydeps"
    ],
    "imports": [
        "pydeps.depgraph",
        "pydeps.mf27"
    ],
    "kind": "imp.PY_SOURCE",
    "name": "pydeps.py2depgraph",
    "path": "pydeps\\py2depgraph.py"
}, ...

Usage:

usage: pydeps [-h] [--config FILE] [--no-config] [--version] [-L LOG] [-v]
              [-o file] [-T FORMAT] [--display PROGRAM] [--noshow]
              [--show-deps] [--show-raw-deps] [--show-dot] [--nodot]
              [--show-cycles] [--debug] [--noise-level INT] [--max-bacon INT]
              [--pylib] [--pylib-all] [--include-missing]
              [-x FNAME [FNAME ...]] [--externals]
              fname
positional arguments:

fname filename

optional arguments:
-h, --help

show this help message and exit

--config FILE

specify config file

--no-config

disable processing of config files

--version

print pydeps version

-L LOG, --log LOG

set log-level to one of CRITICAL, ERROR, WARNING, INFO, DEBUG, NOTSET.

-v, --verbose

be more verbose (-vv, -vvv for more verbosity)

-o file

write output to ‘file’

-T FORMAT

output format (svg|png)

--display PROGRAM

program to use to display the graph (png or svg file depending on the T parameter)

--noshow

don’t call external program to display graph

--show-deps

show output of dependency analysis

--show-raw-deps

show output of dependency analysis before removing skips

--show-dot

show output of dot conversion

--nodot

skip dot conversion

--show-cycles

show only import cycles

--debug

turn on all the show and verbose options

--noise-level INT

exclude sources or sinks with degree greater than noise-level

--max-bacon INT

exclude nodes that are more than n hops away (default=2, 0 -> infinite)

--pylib

include python std lib modules

--pylib-all

include python all std lib modules (incl. C modules)

--x FNAME, --exclude FNAME

input files to skip (multiple file names can be provided)

--externals

create list of direct external dependencies

You can of course import pydeps from Python (look in the tests/test_relative_imports.py file for examples.

Contributing

  1. Fork it

  2. Create your feature branch (git checkout -b my-new-feature)

  3. Commit your changes (git commit -am ‘Add some feature’)

  4. Push to the branch (git push origin my-new-feature)

  5. Create new Pull Request

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydeps-1.6.2.tar.gz (31.2 kB view details)

Uploaded Source

Built Distribution

pydeps-1.6.2-py2-none-any.whl (37.5 kB view details)

Uploaded Python 2

File details

Details for the file pydeps-1.6.2.tar.gz.

File metadata

  • Download URL: pydeps-1.6.2.tar.gz
  • Upload date:
  • Size: 31.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.9.1 pkginfo/1.4.1 requests/2.10.0 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.15.0 CPython/2.7.13

File hashes

Hashes for pydeps-1.6.2.tar.gz
Algorithm Hash digest
SHA256 62935c9f6e738fce0782a3706564dc53ab18488cf86e476713bfd726ca26d81a
MD5 5a2c68c35ea62c4bcc8ce04763c37267
BLAKE2b-256 17446efa376206393f3c793a640c1ff05abb437736671193f9d15037cee38640

See more details on using hashes here.

Provenance

File details

Details for the file pydeps-1.6.2-py2-none-any.whl.

File metadata

  • Download URL: pydeps-1.6.2-py2-none-any.whl
  • Upload date:
  • Size: 37.5 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.9.1 pkginfo/1.4.1 requests/2.10.0 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.15.0 CPython/2.7.13

File hashes

Hashes for pydeps-1.6.2-py2-none-any.whl
Algorithm Hash digest
SHA256 0b3262a17d521a26c9e47156524828bfdfb6d8e4c5eaa8ee374765339cb66a4f
MD5 863294f0d86634f3307a9d32e0a44313
BLAKE2b-256 abf459f189904f783b85816db27573dc9df260256e26879d460172fcf0059064

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page