MCPcopy Index your code
hub / github.com/numpy/numpy / _cache

Method _cache

numpy/lib/_datasource.py:314–338  ·  view source on GitHub ↗

Cache the file specified by path. Creates a copy of the file in the datasource cache.

(self, path)

Source from the content-addressed store, hash-verified

312 return bool(scheme and netloc)
313
314 def _cache(self, path):
315 """Cache the file specified by path.
316
317 Creates a copy of the file in the datasource cache.
318
319 """
320 # We import these here because importing them is slow and
321 # a significant fraction of numpy's total import time.
322 import shutil
323 from urllib.request import urlopen
324
325 upath = self.abspath(path)
326
327 # ensure directory exists
328 if not os.path.exists(os.path.dirname(upath)):
329 os.makedirs(os.path.dirname(upath))
330
331 # TODO: Doesn't handle compressed files!
332 if self._isurl(path):
333 with urlopen(path) as openedurl:
334 with _open(upath, 'wb') as f:
335 shutil.copyfileobj(openedurl, f)
336 else:
337 shutil.copyfile(path, upath)
338 return upath
339
340 def _findfile(self, path):
341 """Searches for ``path`` and returns full path if found.

Callers 1

_findfileMethod · 0.95

Calls 3

abspathMethod · 0.95
_isurlMethod · 0.95
existsMethod · 0.45

Tested by

no test coverage detected