From dc42ab48d2606826ee97a475e523af86940293b2 Mon Sep 17 00:00:00 2001 From: Paul O'Leary McCann Date: Mon, 20 Feb 2023 16:09:34 +0900 Subject: [PATCH] Fix git clone related issues on Windows --- spacy/util.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/spacy/util.py b/spacy/util.py index 38ba7b1b5..fba908fba 100644 --- a/spacy/util.py +++ b/spacy/util.py @@ -1050,8 +1050,15 @@ def make_tempdir() -> Generator[Path, None, None]: """ d = Path(tempfile.mkdtemp()) yield d + + # On Windows, git clones use read-only files, which cause permission errors + # when being deleted. This forcibly fixes permissions. + def force_remove(rmfunc, path, ex): + os.chmod(path, stat.S_IWRITE) + rmfunc(path) + try: - shutil.rmtree(str(d)) + shutil.rmtree(str(d), onerror=force_remove) except PermissionError as e: warnings.warn(Warnings.W091.format(dir=d, msg=e))