MCPcopy
hub / github.com/explosion/spaCy / make_tempdir

Function make_tempdir

spacy/util.py:1117–1137  ·  view source on GitHub ↗

Execute a block in a temporary directory and remove the directory and its contents at the end of the with block. YIELDS (Path): The path of the temp directory.

()

Source from the content-addressed store, hash-verified

1115
1116@contextmanager
1117def make_tempdir() -> Generator[Path, None, None]:
1118 """Execute a block in a temporary directory and remove the directory and
1119 its contents at the end of the with block.
1120 YIELDS (Path): The path of the temp directory.
1121 """
1122 d = Path(tempfile.mkdtemp())
1123 yield d
1124
1125 # On Windows, git clones use read-only files, which cause permission errors
1126 # when being deleted. This forcibly fixes permissions.
1127 def force_remove(rmfunc, path, ex):
1128 os.chmod(path, stat.S_IWRITE)
1129 rmfunc(path)
1130
1131 try:
1132 if sys.version_info >= (3, 12):
1133 shutil.rmtree(str(d), onexc=force_remove)
1134 else:
1135 shutil.rmtree(str(d), onerror=force_remove)
1136 except PermissionError as e:
1137 warnings.warn(Warnings.W091.format(dir=d, msg=e))
1138
1139
1140def is_in_jupyter() -> bool:

Callers 15

_string_to_tmp_fileFunction · 0.90
test_overfitting_IOFunction · 0.90
test_issue4674Function · 0.90
test_issue6730Function · 0.90
test_kb_serializeFunction · 0.90
test_kb_serialize_2Function · 0.90
test_kb_set_entitiesFunction · 0.90
test_kb_serialize_vocabFunction · 0.90
test_vocab_serializationFunction · 0.90
test_kb_serializationFunction · 0.90

Calls

no outgoing calls

Tested by 15

_string_to_tmp_fileFunction · 0.72
test_overfitting_IOFunction · 0.72
test_issue4674Function · 0.72
test_issue6730Function · 0.72
test_kb_serializeFunction · 0.72
test_kb_serialize_2Function · 0.72
test_kb_set_entitiesFunction · 0.72
test_kb_serialize_vocabFunction · 0.72
test_vocab_serializationFunction · 0.72
test_kb_serializationFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…