def _get_per_location_glob(tasks, outputs, regexes):
    """
    Builds a glob listing existing output paths.

    Esoteric reverse engineering, but worth it given that (compared to an
    equivalent contiguousness guarantee by naive complete() checks)
    requests to the filesystem are cut by orders of magnitude, and users
    don't even have to retrofit existing tasks anyhow.
    """
    paths = [o.path for o in outputs]
    # naive, because some matches could be confused by numbers earlier
    # in path, e.g. /foo/fifa2000k/bar/2000-12-31/00
    matches = [r.search(p) for r, p in zip(regexes, paths)]

    for m, p, t in zip(matches, paths, tasks):
        if m is None:
            raise NotImplementedError("Couldn't deduce datehour representation in output path %r of task %s" % (p, t))

    n_groups = len(matches[0].groups())
    # the most common position of every group is likely
    # to be conclusive hit or miss
    positions = [most_common((m.start(i), m.end(i)) for m in matches)[0] for i in range(1, n_groups + 1)]

    glob = list(paths[0])  # FIXME sanity check that it's the same for all paths
    for start, end in positions:
        glob = glob[:start] + ['[0-9]'] * (start - end) + glob[end:]
    # chop off the last path item
    # (wouldn't need to if `hadoop fs -ls -d` equivalent were available)
    return ''.join(glob).rsplit('/', 1)[0]
dataset/ETHPy150Open spotify/luigi/luigi/tools/range.py/_get_per_location_glob/swapped operands of `-`