Utility to check whether the parent directory of the `path` exists. Args: path: input path to check the parent directory. create_dir: if True, when the parent directory doesn't exist, create the directory, otherwise, raise exception.
(path: PathLike, create_dir: bool = True)
| 627 | |
| 628 | |
| 629 | def check_parent_dir(path: PathLike, create_dir: bool = True) -> None: |
| 630 | """ |
| 631 | Utility to check whether the parent directory of the `path` exists. |
| 632 | |
| 633 | Args: |
| 634 | path: input path to check the parent directory. |
| 635 | create_dir: if True, when the parent directory doesn't exist, create the directory, |
| 636 | otherwise, raise exception. |
| 637 | |
| 638 | """ |
| 639 | path = Path(path) |
| 640 | path_dir = path.parent |
| 641 | if not path_dir.exists(): |
| 642 | if create_dir: |
| 643 | path_dir.mkdir(parents=True) |
| 644 | else: |
| 645 | raise ValueError(f"the directory of specified path does not exist: `{path_dir}`.") |
| 646 | |
| 647 | |
| 648 | def save_obj( |
no outgoing calls
searching dependent graphs…