Created
October 3, 2013 06:03
-
-
Save gcmurphy/6805653 to your computer and use it in GitHub Desktop.
Tracing all imports
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From this talk - https://speakerdeck.com/mitsuhiko/didntknow