MCPcopy Create free account
hub / github.com/numpy/numpy / minrelpath

Function minrelpath

numpy/distutils/misc_util.py:232–259  ·  view source on GitHub ↗

Resolve `..` and '.' from path.

(path)

Source from the content-addressed store, hash-verified

230 return mathlibs
231
232def minrelpath(path):
233 """Resolve `..` and '.' from path.
234 """
235 if not is_string(path):
236 return path
237 if '.' not in path:
238 return path
239 l = path.split(os.sep)
240 while l:
241 try:
242 i = l.index('.', 1)
243 except ValueError:
244 break
245 del l[i]
246 j = 1
247 while l:
248 try:
249 i = l.index('..', j)
250 except ValueError:
251 break
252 if l[i-1]=='..':
253 j += 1
254 else:
255 del l[i], l[i-1]
256 j = 1
257 if not l:
258 return ''
259 return os.sep.join(l)
260
261def sorted_glob(fileglob):
262 """sorts output of python glob for https://bugs.python.org/issue30461

Callers 4

test_1Method · 0.90
test_gpathsMethod · 0.90
njoinFunction · 0.85
_fix_pathsFunction · 0.85

Calls 4

is_stringFunction · 0.85
splitMethod · 0.45
indexMethod · 0.45
joinMethod · 0.45

Tested by 2

test_1Method · 0.72
test_gpathsMethod · 0.72