docs: def ensure_dirs(filename):
      """Make sure the directories exist for `filename`."""
      dirname, _ = os.path.split(filename)
      if dirname and not os.path.exists(dirname):
          os.makedirs(dirname)