code: def setup(app):
      app.connect("builder-inited", generate_example_rst)
      app.add_config_value("plot_gallery", True, "html")
  
      # embed links after build is finished
      app.connect("build-finished", embed_code_links)
  
      # Sphinx hack: sphinx copies generated images to the build directory
      #  each time the docs are made.  If the desired image name already
      #  exists, it appends a digit to prevent overwrites.  The problem is,
      #  the directory is never cleared.  This means that each time you build
      #  the docs, the number of images in the directory grows.
      #
      # This question has been asked on the sphinx development list, but there
      #  was no response: http://osdir.com/ml/sphinx-dev/2011-02/msg00123.html
      #
      # The following is a hack that prevents this behavior by clearing the
      #  image build directory each time the docs are built.  If sphinx
      #  changes their layout between versions, this will not work (though
      #  it should probably not cause a crash).  Tested successfully
      #  on Sphinx 1.0.7
      build_image_dir = "_build/html/_images"
      if os.path.exists(build_image_dir):
          filelist = os.listdir(build_image_dir)
          for filename in filelist:
              if filename.endswith("png"):
                  os.remove(os.path.join(build_image_dir, filename))
  
imports: from __future__ import division, print_function
  from time import time
  import ast
  import os
  import re
  import shutil
  import traceback
  import glob
  import sys
  import gzip
  import posixpath
  import subprocess
  import warnings
  from sklearn.externals import six
  from docutils.core import publish_string
  import token
  import tokenize
  import numpy
  import joblib
label_desc: Use image node_id 15 for calling a global function with example usage: setup(app) without return types