Skip to main content

Checks whether imported packages are declared in

Project description

This package provides a dependencychecker script that checks whether an egg declares all packages it imports in its


dependencychecker [-h] [-v] [-z] package

Checks whether imported packages are declared in

positional arguments:
  package        setuptools `requirement string`_,
                 e.g. ws.dependencychecker or ws.dependencychecker[test]

optional arguments:
  -h, --help     show this help message and exit
  -v, --verbose  Print all lines importing missing packages
  -z, --zcml     Scan ZCML files
  -m , --mapping   Filename with additional egg-->packages mappings

Supported Python versions: 2.6, 2.7 (3.x is not supported because some dependencies are not ported yet, e.g. zope.component).

Although dependencychecker does not import any files, it needs the package and its dependencies to be on the PYTHONPATH so they are accessible via pkg_resources.working_set.

By default, dependencychecker prints a list of undeclared package names, formatted ready for copy&paste into your’s install_requires list, like this:

$ depcheck ws.dependencychecker

If you want more details, use the verbose mode (pass -v):

$ depcheck ws.dependencychecker -v
/home/wosc/depcheck/src/ws/dependencychecker/tests/ gocept.testing.mock

To use ws.dependencychecker within a buildout, use a snippet like this, for example:

recipe = zc.recipe.egg
eggs =

Eggs that contain several packages

With most eggs, the egg name and the provided package name is the same (e.g. depending on the zope.interface egg will enable you to import zope.interface, but nothing else). Some eggs, however, contain more than one package, and/or packages with different names (e.g. the ZODB3 egg contains the packages ZODB, BTrees, and persistent).

ws.dependencychecker has a few heuristics built-in (ZODB, setuptools) to deal with that, but when that’s not enough for your project, you can pass in a mapping file of the following format:


So in the ZODB example (which is actually built-in), that looks like:


You don’t need to repeat the egg name itself, so in the case of setuptools (which also contains pkg_resources), that looks like:


Known limitations

  • Only recognizes modules of the standard library for Python 2.7 at the moment.

  • The built-in mappings for eggs that include several or differently named packages are quite limited. Suggestions welcome!

  • Does not recognize multiple packages imported on a single line (import foo, bar will only pick up foo), but this spelling is frowned upon by PEP 8, anyway.

  • Wrongly recognizes includes within multiline comments in ZCML.

  • Does not support scanning zipped eggs.


The source code is available in the mercurial repository at

Please report any bugs you find to Wolfgang Schnerring.


1.1.1 (2011-12-15)

  • Made compatible with Python-2.6

1.1 (2011-12-09)

  • Consolidate package names into egg names (e.g. –> zope.traversing)

  • Allow specifying additional egg–>package mappings.

  • Support scanning of ZCML files.

  • Change default output to grouped mode ready for copy&paste; add verbose mode.

1.0 (2011-12-06)

  • first release.

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

ws.dependencychecker-1.1.1.tar.gz (11.0 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page