Closed ChillarAnand closed 8 years ago
Are you using master? Under master, this works for me. If you can try it, let me know if it works.
If not, I believe this is actually a misclassification of django, treating it as a local import for some reason.
If you look in your importmagic index.json file, you should be able to see each packages location under the key .location
.
I just released 0.1.5 which has a lot of fixes. I'm going to close this under the assumption that the issues are fixed. Reopen it if not.
Unfortunately, its not working yet.
In [27]: importmagic.__version__
Out[27]: '0.1.5'
In [28]: python_source = '''
import os
from .forms import Foo
from django.contrib.auth.decorators import login_required
os.path
Foo()
login_required
'''
In [29]: start_line, end_line, import_block = importmagic.get_update(python_source, index, unresolved, unreferenced)
In [30]: import_block
Out[30]: 'import os\n\nfrom .forms import Foo\nfrom django.contrib.auth.decorators import login_required\n\n\n'
Did you check the index?
Yes, it is treating it as local package.
In [12]: index.find('django').location
Out[12]: u'L'
In latest version, it is identifying django as 3rd party package. Still ordering doesn't change.
I can't replicate this. It's working fine for me:
$ python -mimportmagic.index > index.json
Then:
>>> python_source = '''
import os
from .forms import Foo
from django.contrib.auth.decorators import login_required
os.path
Foo()
login_required
'''
>>> scope = importmagic.Scope.from_source(python_source)
>>> unresolved, unreferenced = scope.find_unresolved_and_unreferenced_symbols()
>>> with open('index.json') as fd:
index = importmagic.SymbolIndex.deserialize(fd)
...:
>>> start_line, end_line, import_block = importmagic.get_update(python_source, index, unresolved, unreferenced)
>>> print import_block
import os
from django.contrib.auth.decorators import login_required
from .forms import Foo
>>>
Here is a test file
When i run import fixup, it changes to
But it should be