From ccbaaa3b3c439035ae324156c7d5e32630223823 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danie=CC=88l=20de=20Kok?= Date: Wed, 25 Jan 2023 13:17:39 +0100 Subject: [PATCH] Also use `TemporaryDirectory` in `git_checkout` --- spacy/cli/_util.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/spacy/cli/_util.py b/spacy/cli/_util.py index 228bd21f6..12aec8267 100644 --- a/spacy/cli/_util.py +++ b/spacy/cli/_util.py @@ -1,3 +1,4 @@ +from tempfile import TemporaryDirectory from typing import Dict, Any, Union, List, Optional, Tuple, Iterable from typing import TYPE_CHECKING, overload import sys @@ -405,13 +406,14 @@ def git_checkout( f"temporarily. To only download the files needed, make sure " f"you're using Git v2.22 or above." ) - with make_tempdir() as tmp_dir: - cmd = f"git -C {tmp_dir} clone {repo} . -b {branch}" + with TemporaryDirectory() as tmp_dir: + tmp_path = Path(tmp_dir) + cmd = f"git -C {tmp_path} clone {repo} . -b {branch}" run_command(cmd, capture=True) # We need Path(name) to make sure we also support subdirectories try: - source_path = tmp_dir / Path(subpath) - if not is_subpath_of(tmp_dir, source_path): + source_path = tmp_path / Path(subpath) + if not is_subpath_of(tmp_path, source_path): err = f"'{subpath}' is a path outside of the cloned repository." msg.fail(err, repo, exits=1) if os.path.isdir(source_path):