MCPcopy Index your code
hub / github.com/RustPython/RustPython / relative_to

Method relative_to

Lib/pathlib/__init__.py:476–496  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers 15

create_archiveFunction · 0.45
setUpClassMethod · 0.45
check_files_presentMethod · 0.45
_compile_importlibMethod · 0.45
generateFunction · 0.45
walkFunction · 0.45
test_bytesMethod · 0.45
test_relative_toMethod · 0.45
find_eq.pyFile · 0.45

Calls 6

with_segmentsMethod · 0.95
_from_parsed_partsMethod · 0.95
hasattrFunction · 0.85
enumerateFunction · 0.85
strFunction · 0.85
lenFunction · 0.85

Tested by 7

setUpClassMethod · 0.36
check_files_presentMethod · 0.36
_compile_importlibMethod · 0.36
test_bytesMethod · 0.36
test_relative_toMethod · 0.36