title: How do conditionally check if a file exists in Sphinx autoclass template?
body: <p>I am attempting to conditionally include a graphviz file into my autoclass template. Only some of my objects have these files, which is why I want to see whether the file exists before attempting to include it.</p>
  <pre><code>   {% if hasdoc('./../lib/program_data.{{ objname }}.dot') %}
     .. graphviz:: ../../lib/program_data.{{ objname }}.dot
     {% endif %}
  </code></pre>
  <p>I'm getting this error message:</p>
  <pre><code>Extension error (sphinx.ext.autosummary):
  Handler &lt;function process_generate_options at 0x7f8eb92a3880&gt; for event 'builder-inited' threw an exception (exception: 'hasdoc' is undefined)
  </code></pre>
  <p><a href="https://www.sphinx-doc.org/en/master/templating.html#hasdoc" rel="nofollow noreferrer">hasdoc</a> is a helper function listed in the <a href="https://www.sphinx-doc.org/en/master/templating.html" rel="nofollow noreferrer">Sphinx template documentation</a>, but it doesn't seem to be available. Maybe because this is an autoclass template? I also tried os.path.exists(), but got an error saying that os was not defined.</p>
  <p>How do I make this work?</p>