Show More
@@ -129,21 +129,26 b' reloader = ModuleReloader()' | |||
|
129 | 129 | |
|
130 | 130 | import IPython.iplib |
|
131 | 131 | |
|
132 | if 'runcode_old' not in globals(): | |
|
133 | # safeguard against reloading *this* module | |
|
134 | runcode_old = IPython.iplib.InteractiveShell.runcode | |
|
132 | autoreload_enabled = False | |
|
133 | ||
|
134 | def runcode_hook(self): | |
|
135 | if not autoreload_enabled: | |
|
136 | raise IPython.ipapi.TryNext | |
|
137 | try: | |
|
138 | reloader.check() | |
|
139 | except: | |
|
140 | pass | |
|
135 | 141 | |
|
136 | def runcode_new(*a, **kw): | |
|
137 | try: reloader.check() | |
|
138 | except: pass | |
|
139 | return runcode_old(*a, **kw) | |
|
140 | 142 | |
|
141 | 143 | def enable_autoreload(): |
|
142 | IPython.iplib.InteractiveShell.runcode = runcode_new | |
|
144 | global autoreload_enabled | |
|
145 | autoreload_enabled = True | |
|
146 | ||
|
143 | 147 | |
|
144 | 148 | def disable_autoreload(): |
|
145 | IPython.iplib.InteractiveShell.runcode = runcode_old | |
|
146 | ||
|
149 | global autoreload_enabled | |
|
150 | autoreload_enabled = False | |
|
151 | ||
|
147 | 152 | #------------------------------------------------------------------------------ |
|
148 | 153 | # IPython connectivity |
|
149 | 154 | #------------------------------------------------------------------------------ |
@@ -226,5 +231,9 b" def aimport_f(self, parameter_s=''):" | |||
|
226 | 231 | mod = __import__(modname) |
|
227 | 232 | ip.to_user_ns({modname: mod}) |
|
228 | 233 | |
|
229 | ip.expose_magic('autoreload', autoreload_f) | |
|
230 |
ip.expose_magic('a |
|
|
234 | def init(): | |
|
235 | ip.expose_magic('autoreload', autoreload_f) | |
|
236 | ip.expose_magic('aimport', aimport_f) | |
|
237 | ip.set_hook('pre_runcode_hook', runcode_hook) | |
|
238 | ||
|
239 | init() No newline at end of file |
@@ -56,7 +56,7 b' from pprint import PrettyPrinter' | |||
|
56 | 56 | __all__ = ['editor', 'fix_error_editor', 'result_display', |
|
57 | 57 | 'input_prefilter', 'shutdown_hook', 'late_startup_hook', |
|
58 | 58 | 'generate_prompt', 'generate_output_prompt','shell_hook', |
|
59 | 'show_in_pager','pre_prompt_hook'] | |
|
59 | 'show_in_pager','pre_prompt_hook', 'pre_runcode_hook'] | |
|
60 | 60 | |
|
61 | 61 | pformat = PrettyPrinter().pformat |
|
62 | 62 | |
@@ -236,7 +236,8 b' def pre_prompt_hook(self):' | |||
|
236 | 236 | |
|
237 | 237 | return None |
|
238 | 238 | |
|
239 |
def p |
|
|
240 | """ Executed after executing a command """ | |
|
239 | def pre_runcode_hook(self): | |
|
240 | """ Executed before running the (prefiltered) code in IPython """ | |
|
241 | return None | |
|
241 | 242 | |
|
242 | 243 |
@@ -2056,6 +2056,7 b' want to merge them back into the new files.""" % locals()' | |||
|
2056 | 2056 | outflag = 1 # happens in more places, so it's easier as default |
|
2057 | 2057 | try: |
|
2058 | 2058 | try: |
|
2059 | self.hooks.pre_runcode_hook() | |
|
2059 | 2060 | # Embedded instances require separate global/local namespaces |
|
2060 | 2061 | # so they can see both the surrounding (local) namespace and |
|
2061 | 2062 | # the module-level globals when called inside another function. |
General Comments 0
You need to be logged in to leave comments.
Login now