def embed_code_links(app, exception):
 try:
  if (exception is not None):
   return
  print 'Embedding documentation hyperlinks in examples..'
  doc_resolvers = {}
  doc_resolvers['sklearn'] = SphinxDocLinkResolver('http://scikit-learn.org/stable')
  doc_resolvers['matplotlib'] = SphinxDocLinkResolver('http://matplotlib.org')
  doc_resolvers['numpy'] = SphinxDocLinkResolver('http://docs.scipy.org/doc/numpy-1.6.0')
  doc_resolvers['scipy'] = SphinxDocLinkResolver('http://docs.scipy.org/doc/scipy-0.11.0/reference')
  doc_resolvers['pandas'] = SphinxDocLinkResolver('http://pandas.pydata.org')
  doc_resolvers['statsmodels'] = SphinxDocLinkResolver('http://statsmodels.sourceforge.net')
  example_dir = os.path.join(app.builder.srcdir, 'auto_examples')
  html_example_dir = os.path.abspath(os.path.join(app.builder.outdir, 'auto_examples'))
  link_pattern = '<a href="%s">%s</a>'
  orig_pattern = '<span class="n">%s</span>'
  period = '<span class="o">.</span>'
  for (dirpath, _, filenames) in os.walk(html_example_dir):
   for fname in filenames:
    print (' DCTB processing: %s' % fname)
    full_fname = os.path.join(html_example_dir, dirpath, fname)
    subpath = dirpath[(len(html_example_dir) + 1):]
    pickle_fname = os.path.join(example_dir, subpath, (fname[:(-5)] + '_codeobj.pickle'))
    if os.path.exists(pickle_fname):
     with open(pickle_fname, 'rb') as fid:
      example_code_obj = cPickle.load(fid)
     fid.close()
     str_repl = {}
     for (name, cobj) in example_code_obj.iteritems():
      this_module = cobj['module'].split('.')[0]
      if (this_module not in doc_resolvers):
       continue
      link = doc_resolvers[this_module].resolve(cobj, full_fname)
      if (link is not None):
       parts = name.split('.')
       name_html = (orig_pattern % parts[0])
       for part in parts[1:]:
        name_html += (period + (orig_pattern % part))
       str_repl[name_html] = (link_pattern % (link, name_html))
     if (len(str_repl) > 0):
      with open(full_fname, 'rb') as fid:
       lines_in = fid.readlines()
      with open(full_fname, 'wb') as fid:
       for line in lines_in:
        line = line.decode('utf-8')
        for (name, link) in str_repl.iteritems():
         line = line.replace(name, link)
        fid.write(line.encode('utf-8'))
 except urllib2.HTTPError as e:
  print 'The following HTTP Error has occurred:\n'
  print e.code
 except urllib2.URLError as e:
  print '\n...\nWarning: Embedding the documentation hyperlinks requires internet access.\nPlease check your network connection.\nUnable to continue embedding due to a URL Error: \n'
  print e.args
 print '[done]'

def embed_code_links ( app , exception ) : try : if ( exception is not None ) : return print 'Embedding documentation hyperlinks in examples..' doc_resolvers = { } doc_resolvers [ 'sklearn' ] = SphinxDocLinkResolver ( 'http://scikit-learn.org/stable' ) doc_resolvers [ 'matplotlib' ] = SphinxDocLinkResolver ( 'http://matplotlib.org' ) doc_resolvers [ 'numpy' ] = SphinxDocLinkResolver ( 'http://docs.scipy.org/doc/numpy-1.6.0' ) doc_resolvers [ 'scipy' ] = SphinxDocLinkResolver ( 'http://docs.scipy.org/doc/scipy-0.11.0/reference' ) doc_resolvers [ 'pandas' ] = SphinxDocLinkResolver ( 'http://pandas.pydata.org' ) doc_resolvers [ 'statsmodels' ] = SphinxDocLinkResolver ( 'http://statsmodels.sourceforge.net' ) example_dir = os . path . join ( app . builder . srcdir , 'auto_examples' ) html_example_dir = os . path . abspath ( os . path . join ( app . builder . outdir , 'auto_examples' ) ) link_pattern = '<a href="%s">%s</a>' orig_pattern = '<span class="n">%s</span>' period = '<span class="o">.</span>' for ( dirpath , _ , filenames ) in os . walk ( html_example_dir ) : for fname in filenames : print ( ' DCTB processing: %s' % fname ) full_fname = os . path . join ( html_example_dir , dirpath , fname ) subpath = dirpath [ ( len ( html_example_dir ) + 1 ) : ] pickle_fname = os . path . join ( example_dir , subpath , ( fname [ : ( - 5 ) ] + '_codeobj.pickle' ) ) if os . path . exists ( pickle_fname ) : with open ( pickle_fname , 'rb' ) as fid : example_code_obj = cPickle . load ( fid ) fid . close ( ) str_repl = { } for ( name , cobj ) in example_code_obj . iteritems ( ) : this_module = cobj [ 'module' ] . split ( '.' ) [ 0 ] if ( this_module not in doc_resolvers ) : continue link = doc_resolvers [ this_module ] . resolve ( cobj , full_fname ) if ( link is not None ) : parts = name . split ( '.' ) name_html = ( orig_pattern % parts [ 0 ] ) for part in parts [ 1 : ] : name_html += ( period + ( orig_pattern % part ) ) str_repl [ name_html ] = ( link_pattern % ( link , name_html ) ) if ( len ( str_repl ) > 0 ) : with open ( full_fname , 'rb' ) as fid : lines_in = fid . readlines ( ) with open ( full_fname , 'wb' ) as fid : for line in lines_in : line = line . decode ( 'utf-8' ) for ( name , link ) in str_repl . iteritems ( ) : line = line . replace ( name , link ) fid . write ( line . encode ( 'utf-8' ) ) except urllib2 . HTTPError as e : print 'The following HTTP Error has occurred:\n' print e . code except urllib2 . URLError as e : print '\n...\nWarning: Embedding the documentation hyperlinks requires internet access.\nPlease check your network connection.\nUnable to continue embedding due to a URL Error: \n' print e . args print '[done]'
embed hyperlinks to documentation into example code .