Skip to content

Commit 34de26a

Browse files
author
Austin Bingham
committed
Only using ultan on 3.4+
1 parent 7750fea commit 34de26a

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55

66
install_requires = [
77
'rope',
8-
'ultan'
98
]
109

1110
if sys.version_info < (3, 4):
1211
install_requires.append('enum34')
12+
else:
13+
# We only enable ultan stuff in 3.4+
14+
install_requires.append('ultan')
1315

1416

1517
def local_file(*name):

traad/rope/auto_import.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,39 @@
1+
from logging import getLogger
2+
13
from rope.base.worder import get_name_at
24
from rope.contrib.autoimport import AutoImport
3-
from ultan.name_index import NameIndex
5+
6+
log = getLogger()
7+
8+
9+
# We use different name-fetching backends depending on whether ultan is
10+
# available or not.
11+
try:
12+
from ultan.name_index import NameIndex
13+
14+
class NameGetter:
15+
def __init__(self):
16+
self.name_index = NameIndex()
17+
18+
def get_names(self, name):
19+
return self.name_index.get_names(name)
20+
21+
except ImportError:
22+
log.info('Ultan not available. Falling back to rope auto-import.')
23+
24+
# We only really come down this path if we're on python 2.7, so we inherit
25+
# from object to make super work later. This is a little shady, but that's
26+
# how I roll.
27+
class NameGetter(object):
28+
def get_names(self, name):
29+
return self.auto_import.import_assist(name)
430

531

6-
class AutoImportMixin:
32+
class AutoImportMixin(NameGetter):
733
def __init__(self):
34+
super(AutoImportMixin, self).__init__()
835
self._auto_import = None
9-
self.name_index = NameIndex()
36+
self.name_getter = NameGetter()
1037

1138
@property
1239
def auto_import(self):
@@ -20,9 +47,8 @@ def get_imports(self, path, offset):
2047
print(r.path)
2148
res = self.get_resource(path)
2249
name = get_name_at(res, offset)
23-
imports = tuple(self.name_index.get_names(name))
50+
imports = tuple(self.get_names(name))
2451
location = self.auto_import.find_insertion_line(res.read())
25-
print(res, name, imports, location)
2652
return {
2753
'imports': imports,
2854
'location': location

0 commit comments

Comments
 (0)