code: def setup(self):
      # Get configuration values.
      (
          savefig_dir,
          source_dir,
          rgxin,
          rgxout,
          promptin,
          promptout,
          mplbackend,
          exec_lines,
          hold_count,
      ) = self.get_config_options()
  
      try:
          os.makedirs(savefig_dir)
      except OSError as e:
          if e.errno != errno.EEXIST:
              raise
  
      if self.shell is None:
          # We will be here many times.  However, when the
          # EmbeddedSphinxShell is created, its interactive shell member
          # is the same for each instance.
  
          if mplbackend and "matplotlib.backends" not in sys.modules:
              import matplotlib
  
              matplotlib.use(mplbackend)
  
          # Must be called after (potentially) importing matplotlib and
          # setting its backend since exec_lines might import pylab.
          self.shell = EmbeddedSphinxShell(exec_lines)
  
          # Store IPython directive to enable better error messages
          self.shell.directive = self
  
      # reset the execution count if we haven't processed this doc
      # NOTE: this may be borked if there are multiple seen_doc tmp files
      # check time stamp?
      if not self.state.document.current_source in self.seen_docs:
          self.shell.IP.history_manager.reset()
          self.shell.IP.execution_count = 1
          self.seen_docs.add(self.state.document.current_source)
  
      # and attach to shell so we don't have to pass them around
      self.shell.rgxin = rgxin
      self.shell.rgxout = rgxout
      self.shell.promptin = promptin
      self.shell.promptout = promptout
      self.shell.savefig_dir = savefig_dir
      self.shell.source_dir = source_dir
      self.shell.hold_count = hold_count
  
      # setup bookmark for saving figures directory
      self.shell.process_input_line(
          "bookmark ipy_savedir %s" % savefig_dir, store_history=False
      )
      self.shell.clear_cout()
  
      return rgxin, rgxout, promptin, promptout
  
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 2 for calling the IPythonDirective obj's underlying member method code with example usage: obj.setup() and returns: rgxin,  rgxout,  promptin,  promptout