Friday, July 24, 2009

» Find python dependencies

When building Python packages, one recurrent and very tedious task is to analyze what dependencies each upstream project has. As we can't apply ldd as with C/C++, nor something like jdepend as with Java, and because I'm lazy and don't like doing repetitive stuff, I've hacked a little script that uses some heuristics to try to find out by itself what a bunch of python sources require. It does so by grepping the import statements (in various forms) in all .py files under the current directory, and then tries to resolve them to .py files under the Python lib directory (e.g. /usr/lib64/python2.6, although it finds out what that directory is by poking Python itself, no assumptions made there) and map those files onto RPM packages (by simply using rpm -qf). Again, simple and stupid, and the ANSI colouring assumes a dark terminal background ;), but you might want to give it a try and you even might find it useful. The (Perl) script is here: fpydep Sample output (make sure to have your browser on UTF-8 encoding):
 WARN  failed to resolve json
 WARN  failed to resolve simplejson
Resolved:
Requires: python-xml

Locals:
services
surl
surl.services
surl.surl
surl.version
version

Failed to resolve python files for the following imports:
json
simplejson
If anyone is aware of a more thorough approach to doing that, please let me know :)

Labels: , ,

0 Comments:

Post a Comment

<< Home