Find all the unique imports in your library, automatically, because who likes do it by hand? Keeping track of imports in a rapidly evolving library is a terrible chore for which I have great distaste.
depfinder
is not yet on pypi. For now, clone it from github and install it:
git clone git@github.com:ericdill/depfinder cd depfinder python setup.py install
Then use it!
python -c " import depfinder; tups = list(depfinder.iterate_over_library('.')); for tup in tups: print(tup)"
You should see
('setup', './setup.py', ImportCatcher: {'required': {'setuptools'}}) ('test', './test.py', ImportCatcher: {'required': {'depfinder'}}) ('depfinder', './depfinder.py', ImportCatcher: {'required': {'stdlib_list'}, 'builtin': {'__future__', 'ast', 'sys', 'os'}})
iterate_over_library
is a function that yields tuples of module_name
,
full_path_to_module
and ImportCatcher
objects.
module_name
is the name of the module (i.e., the file name without the.py
suffix)full_path_to_module
is the full path to the fileImportCatcher
is a data bucket for information that was obtained by rendering themodule_name
as an Abstract Syntax Tree (AST) and searching the tree for import nodes.