Skip to content

Instantly share code, notes, and snippets.

@ChillarAnand
Created March 9, 2016 12:49
Show Gist options
  • Select an option

  • Save ChillarAnand/afdd80b8e8ac1429dfd6 to your computer and use it in GitHub Desktop.

Select an option

Save ChillarAnand/afdd80b8e8ac1429dfd6 to your computer and use it in GitHub Desktop.
imp
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