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