def write_backreferences(seen_backrefs, gallery_conf, target_dir, fname, snippet):
 example_file = os.path.join(target_dir, fname)
 build_target = os.path.relpath(target_dir, gallery_conf['src_dir'])
 backrefs = scan_used_functions(example_file, gallery_conf)
 for backref in backrefs:
  include_path = os.path.join(gallery_conf['src_dir'], gallery_conf['mod_example_dir'], ('%s.examples' % backref))
  seen = (backref in seen_backrefs)
  with open(include_path, ('a' if seen else 'w')) as ex_file:
   if (not seen):
    heading = ('\n\nExamples using ``%s``' % backref)
    ex_file.write((heading + '\n'))
    ex_file.write((('^' * len(heading)) + '\n'))
   ex_file.write(_thumbnail_div(build_target, fname, snippet, is_backref=True))
   seen_backrefs.add(backref)

def write_backreferences ( seen_backrefs , gallery_conf , target_dir , fname , snippet ) : example_file = os . path . join ( target_dir , fname ) build_target = os . path . relpath ( target_dir , gallery_conf [ 'src_dir' ] ) backrefs = scan_used_functions ( example_file , gallery_conf ) for backref in backrefs : include_path = os . path . join ( gallery_conf [ 'src_dir' ] , gallery_conf [ 'mod_example_dir' ] , ( '%s.examples' % backref ) ) seen = ( backref in seen_backrefs ) with open ( include_path , ( 'a' if seen else 'w' ) ) as ex_file : if ( not seen ) : heading = ( '\n\nExamples using ``%s``' % backref ) ex_file . write ( ( heading + '\n' ) ) ex_file . write ( ( ( '^' * len ( heading ) ) + '\n' ) ) ex_file . write ( _thumbnail_div ( build_target , fname , snippet , is_backref = True ) ) seen_backrefs . add ( backref )
writes down back reference files .