##// END OF EJS Templates
Fix bug where exec_lines was ignored within ipython directive.
chebee7i -
Show More
@@ -239,8 +239,6 b' class EmbeddedSphinxShell(object):'
239
239
240 # Create config object for IPython
240 # Create config object for IPython
241 config = Config()
241 config = Config()
242 config.Global.display_banner = False
243 config.Global.exec_lines = exec_lines
244 config.InteractiveShell.autocall = False
242 config.InteractiveShell.autocall = False
245 config.InteractiveShell.autoindent = False
243 config.InteractiveShell.autoindent = False
246 config.InteractiveShell.colors = 'NoColor'
244 config.InteractiveShell.colors = 'NoColor'
@@ -251,8 +249,10 b' class EmbeddedSphinxShell(object):'
251 pdir = os.path.join(tmp_profile_dir,profname)
249 pdir = os.path.join(tmp_profile_dir,profname)
252 profile = ProfileDir.create_profile_dir(pdir)
250 profile = ProfileDir.create_profile_dir(pdir)
253
251
254 # Create and initialize ipython, but don't start its mainloop
252 # Create and initialize global ipython, but don't start its mainloop.
253 # This will persist across different EmbededSphinxShell instances.
255 IP = InteractiveShell.instance(config=config, profile_dir=profile)
254 IP = InteractiveShell.instance(config=config, profile_dir=profile)
255
256 # io.stdout redirect must be done *after* instantiating InteractiveShell
256 # io.stdout redirect must be done *after* instantiating InteractiveShell
257 io.stdout = self.cout
257 io.stdout = self.cout
258 io.stderr = self.cout
258 io.stderr = self.cout
@@ -278,6 +278,10 b' class EmbeddedSphinxShell(object):'
278 # pyplot as plt so we can make a call to the plt.gcf().savefig
278 # pyplot as plt so we can make a call to the plt.gcf().savefig
279 self._pyplot_imported = False
279 self._pyplot_imported = False
280
280
281 # Prepopulate the namespace.
282 for line in exec_lines:
283 self.process_input_line(line, store_history=False)
284
281 def clear_cout(self):
285 def clear_cout(self):
282 self.cout.seek(0)
286 self.cout.seek(0)
283 self.cout.truncate(0)
287 self.cout.truncate(0)
@@ -611,12 +615,17 b' class IPythonDirective(Directive):'
611 promptout, mplbackend, exec_lines) = self.get_config_options()
615 promptout, mplbackend, exec_lines) = self.get_config_options()
612
616
613 if self.shell is None:
617 if self.shell is None:
614 self.shell = EmbeddedSphinxShell(exec_lines)
618
615 if mplbackend:
619 if mplbackend:
616 # Each ipython code-block is run in a separate process.
617 import matplotlib
620 import matplotlib
621 # Repeated calls to use() will not hurt us since `mplbackend`
622 # is the same each time.
618 matplotlib.use(mplbackend)
623 matplotlib.use(mplbackend)
619
624
625 # Must be called after (potentially) importing matplotlib and
626 # setting its backend since exec_lines might import pylab.
627 self.shell = EmbeddedSphinxShell(exec_lines)
628
620 # reset the execution count if we haven't processed this doc
629 # reset the execution count if we haven't processed this doc
621 #NOTE: this may be borked if there are multiple seen_doc tmp files
630 #NOTE: this may be borked if there are multiple seen_doc tmp files
622 #check time stamp?
631 #check time stamp?
General Comments 0
You need to be logged in to leave comments. Login now