Created
March 9, 2016 12:49
-
-
Save ChillarAnand/afdd80b8e8ac1429dfd6 to your computer and use it in GitHub Desktop.
imp
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 importmagic | |
| print('loading index') | |
| index = importmagic.SymbolIndex() | |
| index.build_index(sys.path) | |
| with open('index.json', 'w') as fd: | |
| index.serialize(fd) | |
| python_source = ''' | |
| import logging | |
| import time | |
| import mymod | |
| ''' | |
| scope = importmagic.Scope.from_source(python_source) | |
| unresolved, unreferenced = scope.find_unresolved_and_unreferenced_symbols() | |
| start_line, end_line, import_block = importmagic.get_update(python_source, index, unresolved, unreferenced) | |
| print(python_source) | |
| print(import_block) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment