MCPcopy
hub / github.com/dask/dask / filetexts

Function filetexts

dask/utils.py:465–497  ·  view source on GitHub ↗

Dumps a number of textfiles to disk Parameters ---------- d : dict a mapping from filename to text like {'a.csv': '1,1\n2,2'} Since this is meant for use in tests, this context manager will automatically switch to a temporary current directory, to avoid race conditi

(d, open=open, mode="t", use_tmpdir=True)

Source from the content-addressed store, hash-verified

463
464@contextmanager
465def filetexts(d, open=open, mode="t", use_tmpdir=True):
466 """Dumps a number of textfiles to disk
467
468 Parameters
469 ----------
470 d : dict
471 a mapping from filename to text like {'a.csv': '1,1\n2,2'}
472
473 Since this is meant for use in tests, this context manager will
474 automatically switch to a temporary current directory, to avoid
475 race conditions when running tests in parallel.
476 """
477 with tmp_cwd() if use_tmpdir else nullcontext():
478 for filename, text in d.items():
479 try:
480 os.makedirs(os.path.dirname(filename))
481 except OSError:
482 pass
483 f = open(filename, f"w{mode}")
484 try:
485 f.write(text)
486 finally:
487 try:
488 f.close()
489 except AttributeError:
490 pass
491
492 yield list(d)
493
494 for filename in d:
495 if os.path.exists(filename):
496 with suppress(OSError):
497 os.remove(filename)
498
499
500def concrete(seq):

Callers 15

test_read_bytesFunction · 0.90
test_parse_sample_bytesFunction · 0.90
test_with_urlsFunction · 0.90
test_with_pathsFunction · 0.90
test_read_bytes_blockFunction · 0.90

Calls 4

tmp_cwdFunction · 0.85
closeMethod · 0.80
removeMethod · 0.80
itemsMethod · 0.45

Tested by 15

test_read_bytesFunction · 0.72
test_parse_sample_bytesFunction · 0.72
test_with_urlsFunction · 0.72
test_with_pathsFunction · 0.72
test_read_bytes_blockFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…