code: def validate(py):
      """Validate the format of a tutobook script.
  
      Specifically:
          - validate headers
          - validate style with black
      """
      lines = py.split("\n")
      if not lines[0].startswith('"""'):
          raise ValueError(
              'Missing `"""`-fenced header at top of script.'
          )
      if not lines[1].startswith("Title: "):
          raise ValueError("Missing `Title:` field.")
      if not lines[2].startswith("Author: ") and not lines[
          2
      ].startswith("Authors: "):
          raise ValueError("Missing `Author:` field.")
      if not lines[3].startswith("Date created: "):
          raise ValueError("Missing `Date created:` field.")
      if not lines[4].startswith("Last modified: "):
          raise ValueError("Missing `Last modified:` field.")
      if not lines[5].startswith("Description: "):
          raise ValueError("Missing `Description:` field.")
      description = lines[5][len("Description: ") :]
      if not description:
          raise ValueError("Missing `Description:` field content.")
      if not description[0] == description[0].upper():
          raise ValueError(
              "Description field content must be capitalized."
          )
      if not description[-1] == ".":
          raise ValueError(
              "Description field content must end with a period."
          )
      if len(description) > 100:
          raise ValueError(
              "Description field content must be less than 100 chars."
          )
      for i, line in enumerate(lines):
          if (
              line.startswith('"""')
              and line.endswith('"""')
              and len(line) > 3
          ):
              raise ValueError(
                  'Do not use single line `"""`-fenced comments. '
                  "Encountered at line %d" % (i,)
              )
      for i, line in enumerate(lines):
          if line.endswith(" "):
              raise ValueError(
                  "Found trailing space on line %d; line: `%s`"
                  % (i, line)
              )
      # Validate style with black
      fpath = "/tmp/" + str(random.randint(1e6, 1e7)) + ".py"
      f = open(fpath, "w")
      pre_formatting = "\n".join(lines)
      f.write(pre_formatting)
      f.close()
      os.system("black " + fpath)
      f = open(fpath)
      formatted = f.read()
      f.close()
      os.remove(fpath)
      if formatted != pre_formatting:
          raise ValueError(
              "You python file did not follow `black` conventions. "
              "Run `black your_file.py` to autoformat it."
          )
  
file_path: icevision/docs/tutobooks.py
imports: import json
  import os
  import random
  import shutil
  import sys
  from pathlib import Path
label_desc: Use image node_id 5 for calling a global function with example usage: validate(py) without return types