From a36d0ff28f1cc4c22a26c98920d2ac1219191534 Mon Sep 17 00:00:00 2001 From: Paul O'Leary McCann Date: Thu, 26 Jan 2023 14:41:14 +0900 Subject: [PATCH] Try TemporaryDirectory This should work everywhere except Win <=3.7. --- spacy/util.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/spacy/util.py b/spacy/util.py index 55de96093..fec53c69f 100644 --- a/spacy/util.py +++ b/spacy/util.py @@ -1032,19 +1032,10 @@ def make_tempdir() -> Generator[Path, None, None]: YIELDS (Path): The path of the temp directory. """ - d = Path(tempfile.mkdtemp()) - # On Windows, attempts to delete a git directory fail with permissions - # errors due to read only / hidden files. This mainly addresses that issue. - def _fix_perms(func, path, exc_info): - # IWUSR = give user write permission - os.chmod(path, stat.S_IWUSR) - # func is the function that gave the error, so it behaves like rmtree. - func(path) - - yield d try: - shutil.rmtree(str(d), ignore_errors=False, onerror=_fix_perms) + with tempfile.TemporaryDirectory() as td: + yield td except PermissionError as e: warnings.warn(Warnings.W091.format(dir=d, msg=e))