MCPcopy Create free account
hub / github.com/pymupdf/PyMuPDF / _path_relative_to_root

Method _path_relative_to_root

pipcl.py:1516–1537  ·  view source on GitHub ↗

Returns `(path_abs, path_rel)`, where `path_abs` is absolute path and `path_rel` is relative to `self.root`. Interprets `path` as relative to `self.root` if not absolute. We use `os.path.realpath()` to resolve any links. if `assert_within_root` is true, as

(self, path, assert_within_root=True)

Source from the content-addressed store, hash-verified

1514 return ret
1515
1516 def _path_relative_to_root(self, path, assert_within_root=True):
1517 '''
1518 Returns `(path_abs, path_rel)`, where `path_abs` is absolute path and
1519 `path_rel` is relative to `self.root`.
1520
1521 Interprets `path` as relative to `self.root` if not absolute.
1522
1523 We use `os.path.realpath()` to resolve any links.
1524
1525 if `assert_within_root` is true, assert-fails if `path` is not within
1526 `self.root`.
1527 '''
1528 if os.path.isabs(path):
1529 p = path
1530 else:
1531 p = os.path.join(self.root, path)
1532 p = os.path.realpath(os.path.abspath(p))
1533 if assert_within_root:
1534 assert p.startswith(self.root+os.sep) or p == self.root, \
1535 f'Path not within root={self.root+os.sep!r}: {path=} {p=}'
1536 p_rel = os.path.relpath(p, self.root)
1537 return p, p_rel
1538
1539 def _fromto(self, p):
1540 '''

Callers 1

_fromtoMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected