##// END OF EJS Templates
Merging Pauli's autoreload branch....
Pauli Virtanen -
r2094:9a3a9c54 merge
parent child Browse files
Show More
@@ -252,6 +252,9 b" def autoreload_f(self, parameter_s=''):"
252 %autoreload
252 %autoreload
253 Reload all modules (except those excluded by %aimport) automatically now.
253 Reload all modules (except those excluded by %aimport) automatically now.
254
254
255 %autoreload 0
256 Disable automatic reloading.
257
255 %autoreload 1
258 %autoreload 1
256 Reload all modules imported with %aimport every time before executing
259 Reload all modules imported with %aimport every time before executing
257 the Python code typed.
260 the Python code typed.
@@ -260,14 +263,15 b" def autoreload_f(self, parameter_s=''):"
260 Reload all modules (except those excluded by %aimport) every time
263 Reload all modules (except those excluded by %aimport) every time
261 before executing the Python code typed.
264 before executing the Python code typed.
262
265
263 Reloading Python modules in a reliable way is in general difficult,
266 Reloading Python modules in a reliable way is in general
264 and unexpected things may occur. %autoreload tries to work
267 difficult, and unexpected things may occur. %autoreload tries to
265 around common pitfalls by replacing code objects of functions
268 work around common pitfalls by replacing function code objects and
266 previously in the module with new versions. This makes the following
269 parts of classes previously in the module with new versions. This
267 things to work:
270 makes the following things to work:
268
271
269 - Functions and classes imported via 'from xxx import foo' are upgraded
272 - Functions and classes imported via 'from xxx import foo' are upgraded
270 to new versions when 'xxx' is reloaded.
273 to new versions when 'xxx' is reloaded.
274
271 - Methods and properties of classes are upgraded on reload, so that
275 - Methods and properties of classes are upgraded on reload, so that
272 calling 'c.foo()' on an object 'c' created before the reload causes
276 calling 'c.foo()' on an object 'c' created before the reload causes
273 the new code for 'foo' to be executed.
277 the new code for 'foo' to be executed.
@@ -277,8 +281,10 b" def autoreload_f(self, parameter_s=''):"
277 - Replacing code objects does not always succeed: changing a @property
281 - Replacing code objects does not always succeed: changing a @property
278 in a class to an ordinary method or a method to a member variable
282 in a class to an ordinary method or a method to a member variable
279 can cause problems (but in old objects only).
283 can cause problems (but in old objects only).
284
280 - Functions that are removed (eg. via monkey-patching) from a module
285 - Functions that are removed (eg. via monkey-patching) from a module
281 before it is reloaded are not upgraded.
286 before it is reloaded are not upgraded.
287
282 - C extension modules cannot be reloaded, and so cannot be
288 - C extension modules cannot be reloaded, and so cannot be
283 autoreloaded.
289 autoreloaded.
284
290
@@ -329,8 +335,11 b" def aimport_f(self, parameter_s=''):"
329 except KeyError: pass
335 except KeyError: pass
330 reloader.modules[modname] = True
336 reloader.modules[modname] = True
331
337
332 mod = __import__(modname)
338 # Inject module to user namespace; handle also submodules properly
333 ip.to_user_ns({modname: mod})
339 __import__(modname)
340 basename = modname.split('.')[0]
341 mod = sys.modules[basename]
342 ip.to_user_ns({basename: mod})
334
343
335 def init():
344 def init():
336 ip.expose_magic('autoreload', autoreload_f)
345 ip.expose_magic('autoreload', autoreload_f)
General Comments 0
You need to be logged in to leave comments. Login now