def relpath(target, base=os.curdir):

    base_list = (os.path.abspath(base)).split(os.sep)
    target_list = (os.path.abspath(target)).split(os.sep)

    # Starting from the filepath root, work out how much of the filepath is
    # shared by base and target.
    for i in range(min(len(base_list), len(target_list))):
        if base_list[i] != target_list[i]: break
    else:
        # If we broke out of the loop, i is pointing to the first
        # differing path elements. If we didn't break out of the loop, i
        # is pointing to identical path elements.
        # Increment i so that in all cases it points to the first
        # differing path elements.
        i+=1

    rel_list = [os.pardir] * (len(base_list)-i) + target_list[i:]
    return os.path.join(*rel_list)
Return a relative path to the target from either the current dir or an
dataset/ETHPy150Open enthought/mayavi/mlab_reference.py/relpath