Skip to main content

A Python module that build dependency matrices between other modules.

Project description

Dependenpy

Dependenpy allows you to build a dependency matrix for a set of Python packages. To do this, it reads and searches the source code for import statements.

License

Software licensed under ISC license.

Installation

pip install dependenpy

Usage

Version 3 introduces a command-line tool:

Example:

dependenpy -h

Result:

usage: dependenpy [-d DEPTH] [-l] [-m] [-o OUTPUT] [-v] [-h] PACKAGES [PACKAGES ...]

Command line tool for dependenpy Python package.

positional arguments:
  PACKAGES              The package list. Can be a comma-separated list. Each package must be either a valid path or a package in PYTHONPATH.

optional arguments:
  -d DEPTH, --depth DEPTH
                        Matrix depth. Default: 2 if one package, otherwise 1.
  -i, --enforce-init    Enforce presence of __init__.py when listing
                        directories. Default: false.
  -l, --show-dependencies-list
                        Show the dependencies list. Default: false.
  -m, --show-matrix     Show the matrix. Default: false.
  -o OUTPUT, --output OUTPUT
                        File to write to. Default: stdout.
  -v, --version         Show program's version number and exit.
  -h, --help            Show this help message and exit.

Example:

dependenpy dependenpy
dependenpy dependenpy --depth=2

Result:

             Module | Id ||0|1|2|3|
--------------------+----++-+-+-+-+
dependenpy.__init__ |  0 ||0|0|0|4|
dependenpy.__main__ |  1 ||0|0|1|0|
     dependenpy.cli |  2 ||0|0|0|1|
     dependenpy.dsm |  3 ||0|0|0|0|

Example:

dependenpy -l dependenpy

Result:

Dependency DSM for packages: [dependenpy]
  dependenpy
    __main__
      ! __main__ imports sys (line 13)
      __main__ imports main from dependenpy.cli (line 15)
    dsm
      ! dsm imports ast (line 5)
      ! dsm imports os (line 6)
      ! dsm imports sys (line 7)
      ! dsm imports copy.deepcopy (line 8)
      ! dsm imports importlib.util.find_spec (line 9)
      ! dsm imports os.path.basename (line 10)
      ! dsm imports os.path.dirname (line 10)
      ! dsm imports os.path.exists (line 10)
      ! dsm imports os.path.isdir (line 10)
      ! dsm imports os.path.isfile (line 10)
      ! dsm imports os.path.join (line 10)
      ! dsm imports os.path.splitext (line 10)
    cli
      ! cli imports argparse (line 20)
      ! cli imports sys (line 21)
      cli imports DSM from dependenpy.dsm (line 23)
    __init__
      __init__ imports DSM from dependenpy.dsm (line 11)
      __init__ imports Dependency from dependenpy.dsm (line 11)
      __init__ imports Module from dependenpy.dsm (line 11)
      __init__ imports Package from dependenpy.dsm (line 11)

Example:

dependenpy json,setuptools
dependenpy json setuptools

Result:

    Module | Id ||0 |1 |
-----------+----++--+--+
      json |  0 || 5| 0|
setuptools |  1 || 0|75|

You can also use dependenpy programmatically:

from dependenpy import DSM

# create DSM
dsm = DSM('django')

# transform as matrix, dict of deps or treemap
matrix = dsm.as_matrix(depth=2)
deps = dsm.as_dict()
treemap = dsm.as_treemap()  # soon

# initialize with many packages
dsm = DSM('django', 'meerkat', 'appsettings', 'dependenpy', 'archan')
with open('output', 'w') as output:
    dsm.print(matrix=True, depth=1, dependencies=True, output=output)

# access packages and modules
meerkat = dsm['meerkat']  # or dsm.get('meerkat')
finder = dsm['dependenpy.finder']  # or even dsm['dependenpy']['finder']

# instances of DSM and Package all have print, as_matrix, etc. methods
meerkat.print_matrix(depth=2)

This module was originally design to work in a Django project. The Django package django-meerkat uses it to display the matrices with Highcharts.

Documentation

On ReadTheDocs

Development

To run all the tests: tox

Changelog

3.0.0 (2017-05-23)

This version is a big refactoring. The code is way more object oriented, cleaner, shorter, simpler, smarter, more user friendly- in short: better.

Additional features:

  • command line entry point,

  • runtime static imports are now caught (in functions or classes), as well as import statements (previously only from import).

2.0.3 (2017-04-20)

  • Fix occasional UnicodeEncode when reading UTF-8 file.

  • Handle bad characters in files when parsing with ast.

0.1.0 to 2.0.2 (2016-10-06)

  • Development (alpha then beta version).

0.1.0 (2016-10-06)

  • Alpha release on PyPI.

Project details


Download files

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

Source Distribution

dependenpy-3.0.0.tar.gz (23.2 kB view hashes)

Uploaded Source

Built Distribution

dependenpy-3.0.0-py2.py3-none-any.whl (16.4 kB view hashes)

Uploaded Python 2 Python 3

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