Skip to main content

Display module dependencies

Project description

Documentation Status https://travis-ci.org/thebjorn/pydeps.svg https://coveralls.io/repos/thebjorn/pydeps/badge.png

Python module dependency visualization. This package installs the pydeps command, and normal usage will be to use it from the command line. 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 --show pydeps):

https://dl.dropboxusercontent.com/u/94882440/pydeps.svg

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://dl.dropboxusercontent.com/u/94882440/pydeps-pylib.svg

--max-bacon 2 gives the modules that are at most 2 hops away, and modules that belong together have similar colors. Compare that to the output without the --max-bacon 2 filter:

https://dl.dropboxusercontent.com/u/94882440/pydeps-pylib-all.svg

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://dl.dropboxusercontent.com/u/94882440/pydeps-cycle.svg

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-script.py [-h] [--config FILE] [--no-config] [-v] [-o file]
                    [-T FORMAT] [--display PROGRAM] [--show] [--show-deps]
                    [--show-raw-deps] [--show-dot] [--show-cycles]
                    [--debug] [--noise-level INT] [--max-bacon INT]
                    [--pylib] [--pylib-all] [-x FNAME [FNAME ...]]
                    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
  -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)
  --show                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
  --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
  --pylib               include python std lib modules
  --pylib-all           include python all std lib modules (incl. C modules)
  -x FNAME [FNAME ...], --exclude FNAME [FNAME ...]
                        input files to skip

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.2.1.zip (29.9 kB view details)

Uploaded Source

Built Distributions

pydeps-1.2.1.win32.exe (263.4 kB view details)

Uploaded Source

pydeps-1.2.1-py2-none-any.whl (27.1 kB view details)

Uploaded Python 2

File details

Details for the file pydeps-1.2.1.zip.

File metadata

  • Download URL: pydeps-1.2.1.zip
  • Upload date:
  • Size: 29.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pydeps-1.2.1.zip
Algorithm Hash digest
SHA256 7e228e25bab074ab6eb72023bf3e138360c0eaf3ae8c2b9e9972527ea7a0aff3
MD5 3ab307eb5d432e8b0b21490f5ff757d6
BLAKE2b-256 eefcaaadf4f1815326b28006a0f28c81b4bf5b91efc3fe77a33a758649be8e6d

See more details on using hashes here.

Provenance

File details

Details for the file pydeps-1.2.1.win32.exe.

File metadata

  • Download URL: pydeps-1.2.1.win32.exe
  • Upload date:
  • Size: 263.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pydeps-1.2.1.win32.exe
Algorithm Hash digest
SHA256 872c7165285dc6e97b89c10d9250a5bbd62f8cadb8a9a6071edb69f80b0eb48d
MD5 2284ac8e3f8450d2e6b5aff4d8fbd0e0
BLAKE2b-256 18ad8eac2d6577a62ed36e72d3d1ca6436cfb983060d3ae8b1e054c1cb247e2b

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pydeps-1.2.1-py2-none-any.whl
Algorithm Hash digest
SHA256 403227ca97cd3b1e7fa7903e0b43cd3e2aecbf827af8c74b17eadf524d15a89f
MD5 d1f4187b28381c898449d1ff057f9d39
BLAKE2b-256 012e56bb9a377c19ad581bc675f506a140735ae64620a3cd27f081132100439c

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