From 1e77be3ae3397c2b9d5cea457bfdde46a397acc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saugat=20Pachhai=20=28=E0=A4=B8=E0=A5=8C=E0=A4=97=E0=A4=BE?= =?UTF-8?q?=E0=A4=A4=29?= Date: Mon, 30 May 2022 20:09:04 +0545 Subject: [PATCH] testing: use shutil.copytree with dirs_exist_ok See https://docs.python.org/3/library/shutil.html#shutil.copytree. There is dirs_exist_ok kwarg in Python >3.8. --- dvc/testing/fixtures.py | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/dvc/testing/fixtures.py b/dvc/testing/fixtures.py index dfb18d478..ffae60ee3 100644 --- a/dvc/testing/fixtures.py +++ b/dvc/testing/fixtures.py @@ -27,21 +27,12 @@ __all__ = [ 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 @@ -59,12 +50,7 @@ def make_tmp_dir(tmp_path_factory, request, worker_id): # 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: