class_docstr: Tools for generating an example page from a file
class_docstr_tok: ["Tools","for","generating","an","example","page","from","a","file"]
docstr: Extract a module-level docstring
docstr_tok: ["Extract","a","module-level","docstring"]
code: def extract_docstring(self):
      """Extract a module-level docstring"""
      lines = open(self.filename).readlines()
      start_row = 0
      if lines[0].startswith("#!"):
          lines.pop(0)
          start_row = 1
  
      docstring = ""
      first_par = ""
      line_iter = lines.__iter__()
      tokens = tokenize.generate_tokens(lambda: next(line_iter))
      for tok_type, tok_content, _, (erow, _), _ in tokens:
          tok_type = token.tok_name[tok_type]
          if tok_type in (
              "NEWLINE",
              "COMMENT",
              "NL",
              "INDENT",
              "DEDENT",
          ):
              continue
          elif tok_type == "STRING":
              docstring = eval(tok_content)
              # If the docstring is formatted with several paragraphs,
              # extract the first one:
              paragraphs = "\n".join(
                  line.rstrip() for line in docstring.split("\n")
              ).split("\n\n")
              if len(paragraphs) > 0:
                  first_par = paragraphs[0]
          break
  
      for line in docstring.split("\n"):
          # Capture the first non-empty line of the docstring as title
          if self._title is None or self._title == "":
              self._title = line
  
          # Look for optional gallery_category from docstring
          if self._gallery_category == "":
              m = re.match(r"^_gallery_category: (.*)$", line)
              if m:
                  self._gallery_category = m.group(1)
                  # Remove _gallery_category line from docstring
                  docstring = "\n".join(
                      [
                          l
                          for l in docstring.split("\n")
                          if not l.startswith("_gallery_category")
                      ]
                  )
  
          # Look for optional alternative_info from docstring
          if self._alt_text == "":
              m = re.match(r"^_alt_text: (.*)$", line)
              if m:
                  self._alt_text = m.group(1)
                  # Remove _alt_text line from docstring
                  docstring = "\n".join(
                      [
                          l
                          for l in docstring.split("\n")
                          if not l.startswith("_alt_text")
                      ]
                  )
  
      assert self._title != ""
      self.docstring = docstring
      self.short_desc = first_par
      self.end_line = erow + 1 + start_row
  
imports: import glob
  import os
  import os.path
  import re
  import shutil
  import token
  import tokenize
  from typing import Optional
  import matplotlib
  import matplotlib.pyplot
  from arviz.rcparams import rc_context
  from arviz import rcParams
label_desc: Use image node_id 18 for calling the ExampleGenerator obj's underlying member method code with example usage: obj.extract_docstring() without return types