list python package dependencies without loading them?

denis picture denis · May 20, 2010 · Viewed 23.4k times · Source

Say that python package A requires B, C and D; is there a way to list A → B C D without loading them ?
Requires in the metadata (yolk -M A) are often incomplete, grr.
One can download A.tar / A.egg, then look through A/setup.py, but some of those are pretty gory.

(I'd have thought that getting at least first-level dependencies could be mechanized; even a 98 % solution would be better than avalanching downloads.)

A related question: pip-upgrade-package-without-upgrading-dependencies

Answer

unutbu picture unutbu · May 20, 2010

Snakefood

sfood -fuq package.py | sfood-target-files 

will list the dependencies.

`-f` tells sfood to follow dependencies recursively
`-u` tells sfood to ignore unused imports
`-q` tells sfood to be quiet about debugging information

To filter out modules from the standard library, you could use

sfood -fuq package.py | sfood-filter-stdlib | sfood-target-files 

As you've already noted, if there are other directories you'd like ignored, you can also use the sfood -I flag.