Skip to content

Commit

Permalink
testing: use shutil.copytree with dirs_exist_ok
Browse files Browse the repository at this point in the history
See https://docs.python.org/3/library/shutil.html#shutil.copytree.
There is dirs_exist_ok kwarg in Python >3.8.
  • Loading branch information
skshetry committed May 30, 2022
1 parent 844f77b commit 1e77be3
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions dvc/testing/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,12 @@
CACHE = {} # type: ignore


def _fs_copy(src, dst, ignore=None):
import shutil

if os.path.isdir(src):
shutil.copytree(src, dst, ignore=ignore)
else:
shutil.copy2(src, dst)


@pytest.fixture(scope="session")
def make_tmp_dir(tmp_path_factory, request, worker_id):
def make(
name, *, scm=False, dvc=False, subdir=False
): # pylint: disable=W0621
from shutil import ignore_patterns
from shutil import copytree, ignore_patterns

from scmrepo.git import Git

Expand All @@ -59,12 +50,7 @@ def make(
# ignore sqlite files from .dvc/tmp. We might not be closing the cache
# connection resulting in PermissionErrors in Windows.
ignore = ignore_patterns("cache.db*")
for entry in os.listdir(cache):
_fs_copy(
os.path.join(cache, entry),
os.path.join(path, entry),
ignore=ignore,
)
copytree(cache, path, dirs_exist_ok=True, ignore=ignore)
new_dir = TmpDir(path)
str_path = os.fspath(new_dir)
if dvc:
Expand Down

0 comments on commit 1e77be3

Please sign in to comment.