def parse_gcs_path()

in dataflux_pytorch/lightning/path_utils.py [0:0]


def parse_gcs_path(path: Union[str, Path]) -> Tuple[str, str]:
    if not path:
        raise ValueError("Path cannot be empty")
    input_path = process_input_path(path)
    if not (input_path.startswith("gcs://")
            or input_path.startswith("gs://")):
        raise ValueError("Path needs to begin with gcs:// or gs://")
    input_path = input_path.split("//", maxsplit=1)
    if not input_path or len(input_path) < 2:
        raise ValueError("Bucket name must be non-empty")
    split = input_path[1].split("/", maxsplit=1)
    bucket_name = ""
    if len(split) == 1:
        bucket_name = split[0]
        prefix = ""
    else:
        bucket_name, prefix = split
    if not bucket_name:
        raise ValueError("Bucket name must be non-empty")
    return bucket_name, prefix