Return the relative path to another path identified by the passed arguments. If the operation is not possible (because this is not related to the other path), raise ValueError. The *walk_up* parameter controls whether `..` may be used to resolve the path.
(self, other, *, walk_up=False)
| 476 | return ['.' + ext for ext in self.name.lstrip('.').split('.')[1:]] |
| 477 | |
| 478 | def relative_to(self, other, *, walk_up=False): |
| 479 | """Return the relative path to another path identified by the passed |
| 480 | arguments. If the operation is not possible (because this is not |
| 481 | related to the other path), raise ValueError. |
| 482 | |
| 483 | The *walk_up* parameter controls whether `..` may be used to resolve |
| 484 | the path. |
| 485 | """ |
| 486 | if not hasattr(other, 'with_segments'): |
| 487 | other = self.with_segments(other) |
| 488 | parts = [] |
| 489 | for path in chain([other], other.parents): |
| 490 | if path == self or path in self.parents: |
| 491 | break |
| 492 | elif not walk_up: |
| 493 | raise ValueError(f"{str(self)!r} is not in the subpath of {str(other)!r}") |
| 494 | elif path.name == '..': |
| 495 | raise ValueError(f"'..' segment in {str(other)!r} cannot be walked") |
| 496 | else: |
| 497 | parts.append('..') |
| 498 | else: |
| 499 | raise ValueError(f"{str(self)!r} and {str(other)!r} have different anchors") |
| 500 | parts.extend(self._tail[len(path._tail):]) |
| 501 | return self._from_parsed_parts('', '', parts) |
| 502 | |
| 503 | def is_relative_to(self, other): |
| 504 | """Return True if the path is relative to another path or False. |