svn - Python dependencies? -
is possible programmatically detect dependencies given python project residing in svn?
here twist adds precision, , might useful if find you're checking dependencies of miscellaneous code:
- catches import statements executed code being analyzed.
- automatically excludes system-loaded modules, don't have weed through it.
- also reports symbols imported each module.
code:
import __builtin__ import collections import sys in_use = collections.defaultdict(set) _import = __builtin__.__import__ def _myimport(name, globs=none, locs=none, fromlist=none, level=-1): global in_use if fromlist none: fromlist = [] in_use[name].update(fromlist) return _import(name, globs, locs, fromlist, level) # monkey-patch __import__ setattr(__builtin__, '__import__', _myimport) # import , run target project here , run routine import foobar foobar.do_something() # when finishes running, dump imports print 'modules , symbols imported "foobar":' key in sorted(in_use.keys()): print key name in sorted(in_use[key]): print ' ', name
example foobar
module:
import byteplay import cjson def _other(): os import path sys import modules def do_something(): import hashlib import lxml _other()
output:
modules , symbols imported "foobar": _hashlib array array byteplay cstringio stringio cjson dis findlabels foobar hashlib itertools lxml opcode * __all__ operator os path sys modules types warnings
Comments
Post a Comment