mirror of
https://github.com/explosion/spaCy.git
synced 2025-08-02 19:30:19 +03:00
Try TemporaryDirectory
This should work everywhere except Win <=3.7.
This commit is contained in:
parent
13fe001b15
commit
a36d0ff28f
|
@ -1032,19 +1032,10 @@ def make_tempdir() -> Generator[Path, None, None]:
|
||||||
|
|
||||||
YIELDS (Path): The path of the temp directory.
|
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:
|
try:
|
||||||
shutil.rmtree(str(d), ignore_errors=False, onerror=_fix_perms)
|
with tempfile.TemporaryDirectory() as td:
|
||||||
|
yield td
|
||||||
except PermissionError as e:
|
except PermissionError as e:
|
||||||
warnings.warn(Warnings.W091.format(dir=d, msg=e))
|
warnings.warn(Warnings.W091.format(dir=d, msg=e))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user