Skip to content

Commit 975b381

Browse files
Merge branch 'clear-modules-and-reevaluate'
Conflicts: bpython/curtsiesfrontend/repl.py
2 parents 22e0131 + 62002aa commit 975b381

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

bpython/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def loadini(struct, configfile):
8080
'show_source': 'F2',
8181
'suspend': 'C-z',
8282
'undo': 'C-r',
83+
'reimport': 'F6',
8384
'search': 'C-o',
8485
'up_one_line': 'C-p',
8586
'yank_from_buffer': 'C-y'},
@@ -120,6 +121,7 @@ def loadini(struct, configfile):
120121
struct.show_source_key = config.get('keyboard', 'show_source')
121122
struct.suspend_key = config.get('keyboard', 'suspend')
122123
struct.undo_key = config.get('keyboard', 'undo')
124+
struct.reimport_key = config.get('keyboard', 'reimport')
123125
struct.up_one_line_key = config.get('keyboard', 'up_one_line')
124126
struct.down_one_line_key = config.get('keyboard', 'down_one_line')
125127
struct.cut_to_buffer_key = config.get('keyboard', 'cut_to_buffer')

bpython/curtsiesfrontend/repl.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ def smarter_request_refresh():
248248
self.current_match = None
249249
self.list_win_visible = False
250250

251+
self.original_modules = sys.modules.keys()
252+
251253
self.width = None # will both be set by a window resize event
252254
self.height = None
253255

@@ -408,6 +410,9 @@ def process_event(self, e):
408410
elif e in ("<Shift-TAB>",):
409411
self.on_tab(back=True)
410412
self.rl_history.reset()
413+
elif e in key_dispatch[self.config.reimport_key]:
414+
self.clear_modules_and_reevaluate()
415+
self.update_completion()
411416
elif e in key_dispatch[self.config.undo_key]: #ctrl-r for undo
412417
self.undo()
413418
self.update_completion()
@@ -516,6 +521,14 @@ def send_session_to_external_editor(self, filename=None):
516521
self.current_line = lines[-1][4:]
517522
self.cursor_offset = len(self.current_line)
518523

524+
def clear_modules_and_reevaluate(self):
525+
cursor, line = self.cursor_offset, self.current_line
526+
for modname in sys.modules.keys():
527+
if modname not in self.original_modules:
528+
del sys.modules[modname]
529+
self.reevaluate(insert_into_history=True)
530+
self.cursor_offset, self.current_line = cursor, line
531+
519532
## Handler Helpers
520533
def add_normal_character(self, char):
521534
if len(char) > 1 or is_nop(char):

doc/sphinx/source/configuration-options.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,14 @@ Default: F9
167167

168168
Shows the last output in the systems $PAGER.
169169

170+
reimport
171+
^^^^^^^^
172+
Default: F6
173+
174+
Reruns entire session, reloading all modules by clearing the sys.modules cache.
175+
176+
.. versionadded:: 0.14
177+
170178
save
171179
^^^^
172180
Default: C-s

0 commit comments

Comments
 (0)