(path, start=None)
Return a relative version of a path
Return a relative version of a path
Return a relative version of a path
def relpath(path, start=None):
    """Return a relative version of a path"""
    path = os.fspath(path)
    if isinstance(path, bytes):
        sep = b'\\'
        curdir = b'.'
        pardir = b'..'
    else:
        sep = '\\'
        curdir = '.'
        pardir = '..'

    if start is None:
        start = curdir

    if not path:
        raise ValueError("no path specified")

    start = os.fspath(start)
    try:
        start_abs = abspath(normpath(start))
        path_abs = abspath(normpath(path))
        start_drive, start_rest = splitdrive(start_abs)
        path_drive, path_rest = splitdrive(path_abs)
        if normcase(start_drive) != normcase(path_drive):
            raise ValueError("path is on mount %r, start on mount %r" % (
                path_drive, start_drive))

        start_list = [x for x in start_rest.split(sep) if x]
        path_list = [x for x in path_rest.split(sep) if x]
        # Work out how much of the filepath is shared by start and path.
        i = 0
        for e1, e2 in zip(start_list, path_list):
            if normcase(e1) != normcase(e2):
                break
            i += 1

        rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
        if not rel_list:
            return curdir
        return join(*rel_list)
    except (TypeError, ValueError, AttributeError, BytesWarning, DeprecationWarning):
        genericpath._check_arg_types('relpath', path, start)
        raise
def relpath ( path , start = None ) : path = os . fspath ( path ) if isinstance ( path , bytes ) : sep = b'\\' curdir = b'.' pardir = b'..' else : sep = '\\' curdir = '.' pardir = '..' if start is None : start = curdir if not path : raise ValueError ( "no path specified" ) start = os . fspath ( start ) try : start_abs = abspath ( normpath ( start ) ) path_abs = abspath ( normpath ( path ) ) start_drive , start_rest = splitdrive ( start_abs ) path_drive , path_rest = splitdrive ( path_abs ) if normcase ( start_drive ) != normcase ( path_drive ) : raise ValueError ( "path is on mount %r, start on mount %r" % ( path_drive , start_drive ) ) start_list = [ x for x in start_rest . split ( sep ) if x ] path_list = [ x for x in path_rest . split ( sep ) if x ] # Work out how much of the filepath is shared by start and path. i = 0 for e1 , e2 in zip ( start_list , path_list ) : if normcase ( e1 ) != normcase ( e2 ) : break i += 1 rel_list = [ pardir ] * ( len ( start_list ) - i ) + path_list [ i : ] if not rel_list : return curdir return join ( * rel_list ) except ( TypeError , ValueError , AttributeError , BytesWarning , DeprecationWarning ) : genericpath . _check_arg_types ( 'relpath' , path , start ) raise