code: def _document_examples(path, result_dict={}):
      if not path.endswith(".py"):
          raise ValueError(
              f"Expected a path to Python index file (ending with '.py'), got {path}"
          )
      rst_file = Path(path).with_suffix(".rst")
      doc_contents = _obtain_doc(path)
      tab = " " * 3
      with open(rst_file, "w") as f:
          f.write(doc_contents.get_title())
          f.write("\n")
          f.write(".. toctree::\n")
          for option in doc_contents.options:
              f.write(f"{tab}{option}\n")
          f.write("\n")
          for entry in doc_contents.entries:
              f.write(f"{tab}{entry.name_to_sphinx()}\n")
  
      canonical_path = Path(path)
      base_path = canonical_path.parent
      for entry in doc_contents.entries:
          _collect_references(
              base_path,
              entry.name_to_sphinx(),
              entry.operator_refs,
              result_dict,
          )
          # For Python index files do the recursion on the actual value stored in entry.name
          if entry.python_index:
              _document_examples(
                  str(base_path / entry.name), result_dict
              )
  
      return result_dict
  
file_path: DALI/docs/doc_index.py
imports: from pathlib import Path
label_desc: Use image node_id 7 for calling a global function with example usage: _document_examples(path, result_dict) and returns: result_dict