Skip to content

cli

existing_dir(path)

Check if path points to an existing directory

Source code in ipsl_common/cli.py
15
16
17
18
19
20
21
22
def existing_dir(path: str | Path):
    """Check if path points to an existing directory"""
    path = Path(path)
    if not path.exists():
        raise ArgumentTypeError(f'Path "{str(path)}" doesn\'t exist')
    if not path.is_dir():
        raise ArgumentTypeError(f'Path "{str(path)}" is not a directory')
    return path

existing_file(path)

Check if path points to an existing file

Source code in ipsl_common/cli.py
 5
 6
 7
 8
 9
10
11
12
def existing_file(path: str | Path):
    """Check if path points to an existing file"""
    path = Path(path)
    if not path.exists():
        raise ArgumentTypeError(f'Path "{str(path)}" doesn\'t exist')
    if not path.is_file():
        raise ArgumentTypeError(f'Path "{str(path)}" is not a file')
    return path