Skip to main content

UNKNOWN

Project description

z3c.dependencychecker

Checks which imports are done and compares them to what’s in setup.py and warn when discovering missing or unneeded dependencies.

What it does

z3c.dependencychecker reports on:

  • Unused imports: pyflakes is another tool that does this (and that also reports on missing variables inside the files).

  • Missing (test) requirements: imports without a corresponding requirement in the setup.py. There might be false alarms, but at least you’ve got a (hopefully short) list of items to check.

    Watch out for packages that have a different name than how they’re imported. For instance a requirement on pydns which is used as import DNS in your code: pydns and DNS lead to separate “missing requirements: DNS” and “unneeded requirements: pydns” warnings.

  • Unneeded (test) requirements: requirements in your setup.py that aren’t imported anywhere in your code. You might need them because not everything needs to be imported. It at least gives you a much smaller list to check by hand.

    If something is only imported in a test file, it shouldn’t be in the generic defaults. Currently you don’t get a separate list of requirements that should be moved from the regular to the test requirements.

Credits

z3c.dependencychecker is a different application/packaging of zope’s importchecker utility. It has been used in quite some projects, I grabbed a copy from lovely.recipe’s checkout.

Source code

The source code can be found in zope’s svn repository: http://svn.zope.org/repos/main/z3c.dependencychecker

At the moment, bugs and suggestions can be send to Reinout.

Usage of z3c.dependencychecker

Installation

Either install z3c.dependencychecker globally (easy_install z3c.dependencychecker) or install it in your buildout.

Usage

Run the dependencychecker or bin/dependencychecker script from your project’s root folder and it will report on your dependencies.

By default, it looks in the src/ directory for your sources. Alternatively, you can specify a start directory yourself, for instance '.' if there’s no src/ directory.

We have a sample project in a temp directory:

>>> sample1_dir
'/TESTTEMP/sample1'
>>> ls(sample1_dir)
setup.py
src

For our test, we call the main() method, just like the dependencychecker script would.

>>> import os
>>> os.chdir(sample1_dir)
>>> from z3c.dependencychecker import dependencychecker
>>> dependencychecker.main()
Unused imports
==============
/TESTTEMP/sample1/src/sample1/unusedimports.py:7:  tempfile
/TESTTEMP/sample1/src/sample1/unusedimports.py:4:  zest.releaser
/TESTTEMP/sample1/src/sample1/unusedimports.py:6:  os
<BLANKLINE>
Missing test requirements
=========================
     reinout.hurray
<BLANKLINE>
Unneeded requirements
=====================
     unneeded.req
<BLANKLINE>
Requirements that should be test requirements
=============================================
     needed.by.test
<BLANKLINE>
Unneeded test requirements
==========================
     zope.testing
<BLANKLINE>
Note: requirements are taken from the egginfo dir, so you need
to re-run buildout (or setup.py or whatever) for changes in
setup.py to have effect.
<BLANKLINE>

So z3c.dependencychecker reports on:

  • Unused imports: pyflakes is another tool that does this (and that also reports on missing variables inside the files).

  • Missing (test) requirements: imports without a corresponding requirement in the setup.py. There might be false alarms, but at least you’ve got a (hopefully short) list of items to check.

    Watch out for packages that have a different name than how they’re imported. For instance a requirement on pydns which is used as import DNS in your code: pydns and DNS lead to separate “missing requirements: DNS” and “unneeded requirements: pydns” warnings.

  • Unneeded (test) requirements: requirements in your setup.py that aren’t imported anywhere in your code. You might need them because not everything needs to be imported. It at least gives you a much smaller list to check by hand.

    If something is only imported in a test file, it shouldn’t be in the generic defaults. Currently you don’t get a separate list of requirements that should be moved from the regular to the test requirements.

TODO

  • Add tests for zcml package="another.import" detection.

  • Improve test coverage.

  • Try it on more projects and gather feedback.

  • Add some extra fallbacks for often-used packages like PIL (which is really Imaging when you import it).

  • Optionally check imports inside doctests.

Changelog of z3c.dependencychecker

0.3 (2009-12-08)

  • Sorted “unneeded requirements” reports and filtered out duplicates.

  • Reporting separately on dependencies that should be moved from the regular to the test dependencies.

0.2 (2009-12-08)

  • Added tests. Initial quick test puts coverage at 86%.

  • Fixed bug in test requirement detection.

  • Added documentation.

  • Moved source code to zope’s svn repository.

0.1 (2009-12-02)

  • Also reporting on unneeded imports.

  • Added note on re-running buildout after a setup.py change.

  • Added zcml lookup to detect even more missing imports.

  • Added reporting on missing regular and test imports.

  • Grabbing existing requirements from egginfo directory.

  • Copied over Martijn Faassen’s zope importchecker script.

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

z3c.dependencychecker-0.3.tar.gz (14.4 kB view details)

Uploaded Source

File details

Details for the file z3c.dependencychecker-0.3.tar.gz.

File metadata

File hashes

Hashes for z3c.dependencychecker-0.3.tar.gz
Algorithm Hash digest
SHA256 9fde97823a0b5e3c0166576ac27e987e8a33fc42e11daf5ec7b2d77208f4401c
MD5 31867d9fe2126d9c7444598f55d3c322
BLAKE2b-256 9080efafbaf0fafac3b33d5451ef10097cd9d7078989f14fcb71afc72fc7e969

See more details on using hashes here.

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