Create directories for a file or directory path. If `is_file` is True, always create the parent directory. If False, create the directory itself. When None, treat paths with a suffix as files and others as directories, but suffix-less file names should pass is_file=True to avoid acc
(path: Path, is_file: bool | None = None)
| 572 | |
| 573 | |
| 574 | def ensure_dirs(path: Path, is_file: bool | None = None) -> None: |
| 575 | """Create directories for a file or directory path. |
| 576 | |
| 577 | If `is_file` is True, always create the parent directory. If False, create the |
| 578 | directory itself. When None, treat paths with a suffix as files and others as |
| 579 | directories, but suffix-less file names should pass is_file=True to avoid |
| 580 | accidental directory creation. |
| 581 | """ |
| 582 | if is_file is None: |
| 583 | is_file = bool(path.suffix) |
| 584 | target = path.parent if is_file else path |
| 585 | target.mkdir(parents=True, exist_ok=True) |
| 586 | |
| 587 | |
| 588 | def artifact_dir_for_example(relpath: str, artifacts_dir: Path) -> Path: |
no test coverage detected