Skip to content

Commit db89938

Browse files
author
bob
committed
module completion loading is now done in the background on startup
1 parent 8d33d45 commit db89938

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

bpython/cli.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,12 +1331,6 @@ def tab(self):
13311331
self.print_line(self.s)
13321332
return True
13331333

1334-
if not importcompletion.modules:
1335-
line = self.s.lstrip()
1336-
if line.startswith('from ') or line.startswith('import '):
1337-
self.statusbar.message('Scanning for modules...')
1338-
importcompletion.reload()
1339-
13401334
if not OPTS.auto_display_list and not self.list_win_visible:
13411335
self.complete(tab=True)
13421336
return True
@@ -1699,6 +1693,7 @@ def idle(caller):
16991693

17001694
global stdscr
17011695

1696+
importcompletion.find_coroutine()
17021697
caller.statusbar.check()
17031698

17041699
if DO_RESIZE:

bpython/importcompletion.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727

2828

2929
# The cached list of all known modules
30-
modules = list()
31-
30+
modules = set()
31+
fully_loaded = False
3232

3333
def complete(line, cw):
3434
"""Construct a full list of possibly completions for imports."""
@@ -88,18 +88,29 @@ def find_modules(path):
8888
def find_all_modules(path=None):
8989
"""Return a list with all modules in `path`, which should be a list of
9090
directory names. If path is not given, sys.path will be used."""
91-
modules = set()
9291
if path is None:
9392
modules.update(sys.builtin_module_names)
9493
path = sys.path
9594

9695
for p in path:
9796
modules.update(find_modules(p))
98-
99-
return modules
97+
yield
98+
99+
def find_coroutine():
100+
global fully_loaded
100101

102+
if fully_loaded:
103+
return
104+
105+
try:
106+
find_iterator.next()
107+
except StopIteration:
108+
fully_loaded = True
101109

102110
def reload():
103111
"""Refresh the list of known modules."""
104-
global modules
105-
modules = find_all_modules()
112+
modules.clear()
113+
for _ in find_all_modules():
114+
pass
115+
116+
find_iterator = find_all_modules()

0 commit comments

Comments
 (0)