MCPcopy Index your code
hub / github.com/pymupdf/PyMuPDF / relpath

Function relpath

pipcl.py:3112–3135  ·  view source on GitHub ↗

A safe alternative to os.path.relpath(), avoiding an exception on Windows if the drive needs to change - in this case we use os.path.abspath(). Args: path: Path to be processed. start: Start directory or current directory if None. all

(path, start=None, allow_up=True)

Source from the content-addressed store, hash-verified

3110
3111
3112def relpath(path, start=None, allow_up=True):
3113 '''
3114 A safe alternative to os.path.relpath(), avoiding an exception on Windows
3115 if the drive needs to change - in this case we use os.path.abspath().
3116
3117 Args:
3118 path:
3119 Path to be processed.
3120 start:
3121 Start directory or current directory if None.
3122 allow_up:
3123 If false we return absolute path is <path> is not within <start>.
3124 ''&#x27;
3125 if windows():
3126 try:
3127 ret = os.path.relpath(path, start)
3128 except ValueError:
3129 # os.path.relpath() fails if trying to change drives.
3130 ret = os.path.abspath(path)
3131 else:
3132 ret = os.path.relpath(path, start)
3133 if not allow_up and ret.startswith('../') or ret.startswith('..\\'):
3134 ret = os.path.abspath(path)
3135 return ret
3136
3137
3138def _so_suffix(use_so_versioning=True):

Callers 1

_logFunction · 0.70

Calls 1

windowsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…