code: def extract_toc(path):
      """Helper: Extract toc section from package rst file"""
      with open(path, encoding="utf-8") as f:
          rst = f.read()
  
      # Read out the part containing the toctree
      toctree_start = "\n.. toctree::\n"
      toctree_end = "\nSubmodules"
  
      start_idx = rst.index(toctree_start)
      end_idx = rst.index(toctree_end, start_idx)
      toctree = rst[start_idx + len(toctree_start) : end_idx]
  
      return toctree
  
imports: import os.path
  from collections import namedtuple
  import pytest
  import sphinx.ext.apidoc
  from sphinx.ext.apidoc import main
label_desc: Use image node_id 17 for calling a global function with example usage: extract_toc(path) and returns: toctree