class_docstr: Example Builder for sphinx documentation
docstr: Execute file, save images and standard out, and create RST file
  
  Parameters
  ----------
  path : str
      path to the example file *relative to self.source_dir*
code: def generate_example_rst(self, path):
      """Execute file, save images and standard out, and create RST file
  
      Parameters
      ----------
      path : str
          path to the example file *relative to self.source_dir*
      """
      example_file = os.path.join(self.source_dir, path)
  
      stdout_file = os.path.join(
          self.target_dir, self.stdout_filename(path)
      )
      image_file = os.path.join(
          self.target_dir, self.image_filename(path)
      )
      thumb_file = os.path.join(
          self.target_dir, self.thumb_filename(path)
      )
      rst_file = os.path.join(self.target_dir, self.rst_filename(path))
      py_file = os.path.join(self.target_dir, self.py_filename(path))
  
      # check if we should re-run the example
      if os.path.exists(stdout_file):
          output_modtime = os.stat(stdout_file).st_mtime
          source_modtime = os.stat(example_file).st_mtime
  
          if output_modtime >= source_modtime:
              run_example = self.force_rerun and self.execute_files
          else:
              run_example = self.execute_files
      else:
          run_example = self.execute_files
  
      EF = ExecFile(example_file, execute=run_example)
  
      if run_example:
          # make sure directories exist
          for f in (
              stdout_file,
              image_file,
              thumb_file,
              rst_file,
              py_file,
          ):
              d, f = os.path.split(f)
              if not os.path.exists(d):
                  os.makedirs(d)
  
          # write output
          open(stdout_file, "w").write(EF.output)
  
          # save all figures & thumbnails
          figure_list = EF.save_figures(image_file, thumb_file)
  
          # if no figures are created, we need to make a
          # blank thumb file
          if len(figure_list) == 0:
              shutil.copy("images/blank_image.png", thumb_file % 1)
  
      else:
          figure_list = list(glob.glob(image_file % "[1-9]"))
  
      # copy source code to generated file tree
      shutil.copyfile(example_file, py_file)
  
      figure_list = [
          os.path.relpath(
              f, os.path.join(self.target_dir, os.path.dirname(path))
          )
          for f in figure_list
      ]
  
      fname = os.path.split(path)[1]
      stdout = os.path.split(stdout_file)[1]
      docstring = EF.docstring
      if docstring == "":
          docstring = "\n".join([fname, "-" * len(fname), ""])
  
      rst_file = open(rst_file, "w")
      rst_file.write(
          self.template_example
          % dict(
              sphinx_tag=self.sphinx_tag(path),
              docstring=docstring,
              stdout=stdout,
              fname=fname,
              image_list=self.image_list(figure_list),
              end_line=EF.end_line,
          )
      )
  
imports: import sys
  import os
  import traceback
  import token
  import tokenize
  import gc
  import shutil
  import glob
  import warnings
  import matplotlib
  from matplotlib import image
  from matplotlib import pyplot
label_desc: Use image node_id 17 for calling the ExampleBuilder obj's underlying member method code with example usage: obj.generate_example_rst(path) without return types