Compute the relative path from this node to node `other`. If other is not in this tree, or it's otherwise impossible, raise a ValueError.
(self, other: Self)
| 740 | return "/" + "/".join(names) # type: ignore[arg-type] |
| 741 | |
| 742 | def relative_to(self, other: Self) -> str: |
| 743 | """ |
| 744 | Compute the relative path from this node to node `other`. |
| 745 | |
| 746 | If other is not in this tree, or it's otherwise impossible, raise a ValueError. |
| 747 | """ |
| 748 | if not self.same_tree(other): |
| 749 | raise NotFoundInTreeError( |
| 750 | "Cannot find relative path because nodes do not lie within the same tree" |
| 751 | ) |
| 752 | |
| 753 | this_path = NodePath(self.path) |
| 754 | if any(other.path == parent.path for parent in (self, *self.parents)): |
| 755 | return str(this_path.relative_to(other.path)) |
| 756 | else: |
| 757 | common_ancestor = self.find_common_ancestor(other) |
| 758 | path_to_common_ancestor = other._path_to_ancestor(common_ancestor) |
| 759 | return str( |
| 760 | path_to_common_ancestor / this_path.relative_to(common_ancestor.path) |
| 761 | ) |
| 762 | |
| 763 | def find_common_ancestor(self, other: Self) -> Self: |
| 764 | """ |