MCPcopy Create free account
hub / github.com/ipython/ipython / reload

Method reload

IPython/lib/demo.py:300–334  ·  view source on GitHub ↗

Reload source from disk and initialize state.

(self)

Source from the content-addressed store, hash-verified

298 self.fobj = openpy.open(self.fname)
299
300 def reload(self):
301 """Reload source from disk and initialize state."""
302 self.fload()
303
304 self.src = "".join(openpy.strip_encoding_cookie(self.fobj))
305 src_b = [b.strip() for b in self.re_stop.split(self.src) if b]
306 self._silent = [bool(self.re_silent.findall(b)) for b in src_b]
307 self._auto = [bool(self.re_auto.findall(b)) for b in src_b]
308
309 # if auto_all is not given (def. None), we read it from the file
310 if self.auto_all is None:
311 self.auto_all = bool(self.re_auto_all.findall(src_b[0]))
312 else:
313 self.auto_all = bool(self.auto_all)
314
315 # Clean the sources from all markup so it doesn't get displayed when
316 # running the demo
317 src_blocks = []
318 auto_strip = lambda s: self.re_auto.sub('',s)
319 for i,b in enumerate(src_b):
320 if self._auto[i]:
321 src_blocks.append(auto_strip(b))
322 else:
323 src_blocks.append(b)
324 # remove the auto_all marker
325 src_blocks[0] = self.re_auto_all.sub('',src_blocks[0])
326
327 self.nblocks = len(src_blocks)
328 self.src_blocks = src_blocks
329
330 # also build syntax-highlighted source
331 self.src_blocks_colored = list(map(self.highlight,self.src_blocks))
332
333 # ensure clean namespace and seek offset
334 self.reset()
335
336 def reset(self):
337 """Reset the namespace and seek pointer to restart the demo"""

Callers 1

__init__Method · 0.95

Calls 2

floadMethod · 0.95
resetMethod · 0.95

Tested by

no test coverage detected