def api_doc(section, uses_site=False, **kwargs):
 def add_metadata(api_function):
  doc = api_function._api_doc = getattr(api_function, '_api_doc', {})
  if ('extends' in kwargs):
   kwargs['extends'] = kwargs['extends']._api_doc
  doc.update(kwargs)
  doc['uses_site'] = uses_site
  doc['section'] = section
  doc['lineno'] = api_function.func_code.co_firstlineno
  file_path = abspath(api_function.func_code.co_filename)
  root_dir = g.paths['root']
  if file_path.startswith(root_dir):
   doc['relfilepath'] = relpath(file_path, root_dir)
   doc['source_root_url'] = 'https://github.com/reddit/reddit/blob/master/r2/r2/'
  else:
   for plugin in g.plugins:
    plugin_root = plugin.path
    if (plugin.source_root_url and file_path.startswith(plugin_root)):
     doc['relfilepath'] = relpath(file_path, plugin_root)
     doc['source_root_url'] = plugin.source_root_url
  return api_function
 return add_metadata

def api_doc ( section , uses_site = False , ** kwargs ) : def add_metadata ( api_function ) : doc = api_function . _api_doc = getattr ( api_function , '_api_doc' , { } ) if ( 'extends' in kwargs ) : kwargs [ 'extends' ] = kwargs [ 'extends' ] . _api_doc doc . update ( kwargs ) doc [ 'uses_site' ] = uses_site doc [ 'section' ] = section doc [ 'lineno' ] = api_function . func_code . co_firstlineno file_path = abspath ( api_function . func_code . co_filename ) root_dir = g . paths [ 'root' ] if file_path . startswith ( root_dir ) : doc [ 'relfilepath' ] = relpath ( file_path , root_dir ) doc [ 'source_root_url' ] = 'https://github.com/reddit/reddit/blob/master/r2/r2/' else : for plugin in g . plugins : plugin_root = plugin . path if ( plugin . source_root_url and file_path . startswith ( plugin_root ) ) : doc [ 'relfilepath' ] = relpath ( file_path , plugin_root ) doc [ 'source_root_url' ] = plugin . source_root_url return api_function return add_metadata
add documentation annotations to the decorated function .