Skip to main content

Importchecker finds unused imports in Python modules.

Project description

Importchecker

What is importchecker?

Importchecker is a commandline utility to find unused imports in Python modules.

Its output is “grep-like” (and thus “emacs-friendly”), reporting both the module’s filenames and line numbers where names are imported that are not acually used in the module.

Importchecker will not modify any of the source files. Whether the import needs to be removed is left to the judgement of the developer.

Installation

The importchecker commandline utility can be installed using the easy_install command:

$ sudo easy_install importchecker

The command can then be invoked with either a directory or a Python file:

$ importchecker /path/to/a/source/tree
$ importchecker /path/to/a/source/tree/module.py

Buildout

Projects that make use of zc.buildout for development might find the following buildout.cfg. snippet useful for using the importchecker on the developed codebase:

[buildout]
...
parts = importchecker ...
...

[importchecker]
recipe = zc.recipe.egg
eggs = importchecker
arguments = "${buildout:directory}/src"

Known issues

  • Python-2 support will be dropped in the next major version.

  • No Python-3 support yet.

  • Cases like:

    import foo.bar
    foo.bar.qux = new_value

    will be reported as false positives.

  • One source tree path argument at the time can be passed to the command line utility.

  • Command line argument parsing is rather naïve.

Changes

1.2 (2018-02-21)

  • Start on test coverage.

  • Claim support for Python 2.7, drop claims for earlier versions.

1.1 (2012-01-09)

  • Applied provided by wosc enabling running the import checker on individual python modules not just directories.

  • Report the absolute path for modules when needed, relative paths (relative to the current working directory, that is) when possible.

1.0 (2008-05-06)

  • Initial packaging

  • Make the importchecker work on python 2.5

Credits

  • Martijn Faassen (original developer)

  • Jan-Wijbrand Kolman (packaging)

  • Philipp von Weitershausen

  • various comitters on svn.zope.org.

Download

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

importchecker-1.2.tar.gz (11.5 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