in src/doc_builder/build_doc.py [0:0]
def convert_anchors_mapping_to_sphinx_format(anchors_mapping, package):
"""
Convert the anchor mapping to the format expected by sphinx for the `objects.inv` file.
Args:
anchors_mapping (Dict[`str`, `str`]):
The mapping between anchors for objects in the doc and their location in the doc.
package (`types.ModuleType`):
The package in which to search objects for.
"""
sphinx_refs = []
for anchor, url in anchors_mapping.items():
obj = find_object_in_package(anchor, package)
if isinstance(obj, property):
obj = obj.fget
# Object type
if isinstance(obj, type):
obj_type = "py:class"
elif hasattr(obj, "__name__") and hasattr(obj, "__qualname__"):
obj_type = "py:method" if obj.__name__ != obj.__qualname__ else "py:function"
else:
# Default to function (this part is never hit when building the docs for Transformers and Datasets)
# so it's just to be extra defensive
obj_type = "py:function"
if "#" in url:
sphinx_refs.append(f"{anchor} {obj_type} 1 {url} -")
else:
sphinx_refs.append(f"{anchor} {obj_type} 1 {url}#$ -")
return sphinx_refs