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

Method _cache

numpy/lib/_datasource.py:318–342  ·  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

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