1import os 2 3 4def ensure_directory(path): 5 """Ensure that the parent directory of `path` exists""" 6 dirname = os.path.dirname(path) 7 os.makedirs(dirname, exist_ok=True) 8