Find all the unique imports in your library, automatically, because who likes do it by hand? depfinder uses the ast (Abstract Syntax Tree) module (and more ast docs) to find all :py:class:`ast.Try` and :py:class:`ast.ImportFrom` nodes. These :py:class:`ast.Import` and :py:class:`ast.ImportFrom` nodes are then grouped according to the following categories, in order of decreasing precedence:
- relative
The import is a relative import from within the same library
- builtin
The import is built into the standard library, as determined by scraping the official python docs for the builtins with stdlib-list
- questionable
The import occurs inside any combination of
- :py:class:`ast.Try` (:py:class:`ast.TryExcept` on py27)
- :py:class:`ast.FunctionDef`
- :py:class:`ast.ClassDef`
The module may be importable without these imports, but the it will likely not have full functionality.
- required
The import occurs at the top level of the module and will get executed when the module is imported. These imports must be accounted for in an environment, or the module will not be importable.
depfinder
is on pypi. It is tested against Python 2.7, 3.3, 3.4 and 3.5.
pip install depfinder
It is available via conda.
conda install -c ericdill depfinder
It is also via github.
git clone git@github.com:ericdill/depfinder cd depfinder python setup.py install
or
pip install https://github.com/ericdill/depfinder/zipball/master#egg=depfinder
It has one dependency, stdlib_list, which is where I get the
list of libraries built in to the standard library. stdlib-list
can be
installed via pip
pip install stdlib-list
or conda
conda install -c ericdill stdlib-list
.. currentmodule:: depfinder
.. autofunction:: get_imported_libs
.. autofunction:: iterate_over_library
.. autofunction:: simple_import_search
depfinder
has support for v4 Jupyter notebooks.
.. autofunction:: notebook_path_to_dependencies