Return a relative version of a path
(path, start=None)
| 484 | supports_unicode_filenames = (sys.platform == 'darwin') |
| 485 | |
| 486 | def relpath(path, start=None): |
| 487 | """Return a relative version of a path""" |
| 488 | |
| 489 | if not path: |
| 490 | raise ValueError("no path specified") |
| 491 | |
| 492 | path = os.fspath(path) |
| 493 | if isinstance(path, bytes): |
| 494 | curdir = b'.' |
| 495 | sep = b'/' |
| 496 | pardir = b'..' |
| 497 | else: |
| 498 | curdir = '.' |
| 499 | sep = '/' |
| 500 | pardir = '..' |
| 501 | |
| 502 | if start is None: |
| 503 | start = curdir |
| 504 | else: |
| 505 | start = os.fspath(start) |
| 506 | |
| 507 | try: |
| 508 | start_list = [x for x in abspath(start).split(sep) if x] |
| 509 | path_list = [x for x in abspath(path).split(sep) if x] |
| 510 | # Work out how much of the filepath is shared by start and path. |
| 511 | i = len(commonprefix([start_list, path_list])) |
| 512 | |
| 513 | rel_list = [pardir] * (len(start_list)-i) + path_list[i:] |
| 514 | if not rel_list: |
| 515 | return curdir |
| 516 | return join(*rel_list) |
| 517 | except (TypeError, AttributeError, BytesWarning, DeprecationWarning): |
| 518 | genericpath._check_arg_types('relpath', path, start) |
| 519 | raise |
| 520 | |
| 521 | |
| 522 | # Return the longest common sub-path of the sequence of paths given as input. |
nothing calls this directly
no test coverage detected