class_docstr: An embedded IPython instance to run inside Sphinx
class_docstr_tok: ["An","embedded","IPython","instance","to","run","inside","Sphinx"]
code: def __init__(self, exec_lines=None):
      self.cout = StringIO()
  
      if exec_lines is None:
          exec_lines = []
  
      # Create config object for IPython
      config = Config()
      config.HistoryManager.hist_file = ":memory:"
      config.InteractiveShell.autocall = False
      config.InteractiveShell.autoindent = False
      config.InteractiveShell.colors = "NoColor"
  
      # create a profile so instance history isn't saved
      tmp_profile_dir = tempfile.mkdtemp(prefix="profile_")
      profname = "auto_profile_sphinx_build"
      pdir = os.path.join(tmp_profile_dir, profname)
      profile = ProfileDir.create_profile_dir(pdir)
  
      # Create and initialize global ipython, but don't start its mainloop.
      # This will persist across different EmbededSphinxShell instances.
      IP = InteractiveShell.instance(config=config, profile_dir=profile)
      atexit.register(self.cleanup)
  
      # Store a few parts of IPython we'll need.
      self.IP = IP
      self.user_ns = self.IP.user_ns
      self.user_global_ns = self.IP.user_global_ns
  
      self.input = ""
      self.output = ""
      self.tmp_profile_dir = tmp_profile_dir
  
      self.is_verbatim = False
      self.is_doctest = False
      self.is_suppress = False
  
      # Optionally, provide more detailed information to shell.
      # this is assigned by the SetUp method of IPythonDirective
      # to point at itself.
      #
      # So, you can access handy things at self.directive.state
      self.directive = None
  
      # on the first call to the savefig decorator, we'll import
      # pyplot as plt so we can make a call to the plt.gcf().savefig
      self._pyplot_imported = False
  
      # Prepopulate the namespace.
      for line in exec_lines:
          self.process_input_line(line, store_history=False)
  
imports: from __future__ import print_function
  import atexit
  import errno
  import os
  import re
  import sys
  import tempfile
  import ast
  import warnings
  import shutil
  from docutils.parsers.rst import directives
  from docutils.parsers.rst import Directive
  from traitlets.config import Config
  from IPython import InteractiveShell
  from IPython.core.profiledir import ProfileDir
  from IPython.utils import io
  from IPython.utils.py3compat import PY3
label_desc: Use image node_id 1 to create a new EmbeddedSphinxShell object from inherited base classes: object with example: obj = EmbeddedSphinxShell(exec_lines)