Skip to main content

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.

Release files for ws.dependencychecker 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ws.dependencychecker 1.1.1
File Size Uploaded
ws.dependencychecker-1.1.1.tar.gz 11.0 kB Details

Release files / ws.dependencychecker-1.1.1.tar.gz

Download URL ws.dependencychecker-1.1.1.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e7e922e85e57da9eaef07c1187709031725bb1d978f4a7c1c971d5255e7bafff
BLAKE2b-256 checksum
How to use checksums
1471ed31eb1f14133ed279ea93ad3a4b8a7d969bc1ebe950950fa0a868d587b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.1.1 This release

1 release file

1.1

1 release file

1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page