from pathlib import Path


def _fetch_dirs(bucket, prefix=None):
    """Return set of all directory paths within a GCS bucket blob names
    Parameters
    ----------
    bucket : google.cloud.storage.bucket.Bucket
    Returns
    -------
    all_dirs : set
    """
    all_dirs = set([])

    for blob in bucket.list_blobs(prefix=prefix):
        p = Path(blob.name).parent

        # Skip root dir.
        if p == Path("."):
            continue

        # Parse parent dirs in blob name.
        for i in range(1, len(p.parts) + 1):
            parentdir = str(Path(*p.parts[:i])) + "/"
            all_dirs.add(parentdir)

    return all_dirs