code: def make_all_dirs(path, mode=0o777):
    
    # Avoid races inherent to doing this in two steps (check then create).
    # Python 3 has exist_ok but the approach below works for Python 2+3.
    # https://stackoverflow.com/questions/600268/mkdir-p-functionality-in-python
    try:
      os.makedirs(path, mode=mode)
    except OSError as e:
      if e.errno == errno.EEXIST and os.path.isdir(path):
        pass
      else:
        raise
    return path
docs: Ensure local dir, with all its parent dirs, are created.
    Unlike os.makedirs(), will not fail if the path already exists.