MCPcopy
hub / github.com/numpy/numpy / abspath

Method abspath

numpy/lib/_datasource.py:371–411  ·  view source on GitHub ↗

Return absolute path of file in the DataSource directory. If `path` is a URL, then `abspath` will return either the location the file exists locally or the location it would exist when opened using the `open` method. Parameters ---------- pa

(self, path)

Source from the content-addressed store, hash-verified

369 return None
370
371 def abspath(self, path):
372 """
373 Return absolute path of file in the DataSource directory.
374
375 If `path` is a URL, then `abspath` will return either the location
376 the file exists locally or the location it would exist when opened
377 using the `open` method.
378
379 Parameters
380 ----------
381 path : str or pathlib.Path
382 Can be a local file or a remote URL.
383
384 Returns
385 -------
386 out : str
387 Complete path, including the `DataSource` destination directory.
388
389 Notes
390 -----
391 The functionality is based on `os.path.abspath`.
392
393 """
394 # We do this here to reduce the 'import numpy' initial import time.
395 from urllib.parse import urlparse
396
397 # TODO: This should be more robust. Handles case where path includes
398 # the destpath, but not other sub-paths. Failing case:
399 # path = /home/guido/datafile.txt
400 # destpath = /home/alex/
401 # upath = self.abspath(path)
402 # upath == '/home/alex/home/guido/datafile.txt'
403
404 # handle case where path includes self._destpath
405 splitpath = path.split(self._destpath, 2)
406 if len(splitpath) > 1:
407 path = splitpath[1]
408 scheme, netloc, upath, uparams, uquery, ufrag = urlparse(path)
409 netloc = self._sanitize_relative_path(netloc)
410 upath = self._sanitize_relative_path(upath)
411 return os.path.join(self._destpath, netloc, upath)
412
413 def _sanitize_relative_path(self, path):
414 """Return a sanitised relative path for which

Callers 15

_cacheMethod · 0.95
_findfileMethod · 0.95
existsMethod · 0.95
test_ValidHTTPMethod · 0.95
test_ValidFileMethod · 0.95
test_InvalidHTTPMethod · 0.95
test_InvalidFileMethod · 0.95
test_sandboxingMethod · 0.95
short_pathFunction · 0.45
linter.pyFile · 0.45

Calls 3

splitMethod · 0.80
joinMethod · 0.80

Tested by 10

test_ValidHTTPMethod · 0.76
test_ValidFileMethod · 0.76
test_InvalidHTTPMethod · 0.76
test_InvalidFileMethod · 0.76
test_sandboxingMethod · 0.76
__call__Method · 0.36
test_legacy_pickleMethod · 0.36
test_legacy_pickleFunction · 0.36
test_filenameMethod · 0.36
test_sandboxingMethod · 0.36