##// END OF EJS Templates
Use callbacks system for autoreload
Thomas Kluyver -
Show More
@@ -392,7 +392,6 b' def superreload(module, reload=reload, old_objects={}):'
392 # IPython connectivity
392 # IPython connectivity
393 #------------------------------------------------------------------------------
393 #------------------------------------------------------------------------------
394
394
395 from IPython.core.hooks import TryNext
396 from IPython.core.magic import Magics, magics_class, line_magic
395 from IPython.core.magic import Magics, magics_class, line_magic
397
396
398 @magics_class
397 @magics_class
@@ -491,17 +490,16 b' class AutoreloadMagics(Magics):'
491 # Inject module to user namespace
490 # Inject module to user namespace
492 self.shell.push({top_name: top_module})
491 self.shell.push({top_name: top_module})
493
492
494 def pre_run_code_hook(self, ip):
493 def pre_execute_explicit(self):
495 if not self._reloader.enabled:
494 if self._reloader.enabled:
496 raise TryNext
495 try:
497 try:
496 self._reloader.check()
498 self._reloader.check()
497 except:
499 except:
498 pass
500 pass
501
499
502
500
503 def load_ipython_extension(ip):
501 def load_ipython_extension(ip):
504 """Load the extension in IPython."""
502 """Load the extension in IPython."""
505 auto_reload = AutoreloadMagics(ip)
503 auto_reload = AutoreloadMagics(ip)
506 ip.register_magics(auto_reload)
504 ip.register_magics(auto_reload)
507 ip.set_hook('pre_run_code_hook', auto_reload.pre_run_code_hook)
505 ip.callbacks.register('pre_execute_explicit', auto_reload.pre_execute_explicit)
@@ -23,7 +23,7 b' import nose.tools as nt'
23 import IPython.testing.tools as tt
23 import IPython.testing.tools as tt
24
24
25 from IPython.extensions.autoreload import AutoreloadMagics
25 from IPython.extensions.autoreload import AutoreloadMagics
26 from IPython.core.hooks import TryNext
26 from IPython.core.callbacks import CallbackManager, pre_execute_explicit
27 from IPython.utils.py3compat import PY3
27 from IPython.utils.py3compat import PY3
28
28
29 if PY3:
29 if PY3:
@@ -41,15 +41,14 b' class FakeShell(object):'
41
41
42 def __init__(self):
42 def __init__(self):
43 self.ns = {}
43 self.ns = {}
44 self.callbacks = CallbackManager(self, {'pre_execute_explicit', pre_execute_explicit})
44 self.auto_magics = AutoreloadMagics(shell=self)
45 self.auto_magics = AutoreloadMagics(shell=self)
46 self.callbacks.register('pre_execute_explicit', self.auto_magics.pre_execute_explicit)
45
47
46 register_magics = set_hook = noop
48 register_magics = set_hook = noop
47
49
48 def run_code(self, code):
50 def run_code(self, code):
49 try:
51 self.callbacks.fire('pre_execute_explicit')
50 self.auto_magics.pre_run_code_hook(self)
51 except TryNext:
52 pass
53 exec(code, self.ns)
52 exec(code, self.ns)
54
53
55 def push(self, items):
54 def push(self, items):
General Comments 0
You need to be logged in to leave comments. Login now