Skip to content

Instantly share code, notes, and snippets.

@gcmurphy
Created October 3, 2013 06:03
Show Gist options
  • Select an option

  • Save gcmurphy/6805653 to your computer and use it in GitHub Desktop.

Select an option

Save gcmurphy/6805653 to your computer and use it in GitHub Desktop.
Tracing all imports
import sys
import __builtin__
real_import = __builtin__.__import__
def debug_import(name, locals=None, globals=None, fromlist=None, level=-1):
glob = globals or sys._getframe(1).f_globals
importer_name = glob and glob.get('__name__') or 'unknown'
print('{} imports {}'.format(importer_name, name))
return real_import(name, locals, globals, fromlist, level)
__builtin__.__import__ = debug_import
@gcmurphy
Copy link
Copy Markdown
Author

gcmurphy commented Oct 3, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment