Skip to main content

Checks whether imported packages are declared in setup.py

Project description

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

Usage

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

Checks whether imported packages are declared in setup.py.

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 setup.py’s install_requires list, like this:

$ depcheck ws.dependencychecker
'gocept.testing.mock',

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

$ depcheck ws.dependencychecker -v
/home/wosc/depcheck/src/ws/dependencychecker/tests/test_check.py:4:import gocept.testing.mock

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

[depcheck]
recipe = zc.recipe.egg
eggs =
    ${test:eggs}
    ws.dependencychecker

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:

[egg_name]
package1
package2

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

[ZODB3]
ZODB
BTrees
persistent

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

[setuptools]
pkg_resources

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.

Development

The source code is available in the mercurial repository at http://code.wosc.de/hg/public/ws.dependencychecker.

Please report any bugs you find to Wolfgang Schnerring.

Changelog

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.foo –> 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 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