From 74850fe728b3c5ff693c113cd8e91b708cd67acf Mon Sep 17 00:00:00 2001 From: Aman Sharma Date: Thu, 9 Jan 2020 14:55:49 +0530 Subject: [PATCH] Move `walk_files` to fs.py --- dvc/remote/local.py | 2 +- dvc/utils/__init__.py | 6 ------ dvc/utils/fs.py | 6 ++++++ tests/func/test_checkout.py | 3 ++- tests/unit/remote/test_remote_dir.py | 2 +- tests/unit/utils/test_fs.py | 5 +++++ tests/unit/utils/test_utils.py | 5 ----- 7 files changed, 15 insertions(+), 14 deletions(-) diff --git a/dvc/remote/local.py b/dvc/remote/local.py index 26fabe1e48..602e9d875c 100644 --- a/dvc/remote/local.py +++ b/dvc/remote/local.py @@ -25,9 +25,9 @@ from dvc.utils import file_md5 from dvc.utils import relpath from dvc.utils import tmp_fname -from dvc.utils import walk_files from dvc.compat import fspath_py35 from dvc.utils.fs import move, makedirs, remove +from dvc.utils.fs import walk_files logger = logging.getLogger(__name__) diff --git a/dvc/utils/__init__.py b/dvc/utils/__init__.py index 9a6157ef96..edb77e93bb 100644 --- a/dvc/utils/__init__.py +++ b/dvc/utils/__init__.py @@ -231,12 +231,6 @@ def to_yaml_string(data): return stream.getvalue() -def walk_files(directory): - for root, _, files in os.walk(fspath(directory)): - for f in files: - yield os.path.join(root, f) - - def colorize(message, color=None): """Returns a message in a specified color.""" if not color: diff --git a/dvc/utils/fs.py b/dvc/utils/fs.py index 7a3017b7fb..56f3c9975b 100644 --- a/dvc/utils/fs.py +++ b/dvc/utils/fs.py @@ -201,3 +201,9 @@ def copyfile(src, dest, no_progress_bar=False, name=None): break fdest.write(buf) pbar.update(len(buf)) + + +def walk_files(directory): + for root, _, files in os.walk(fspath(directory)): + for f in files: + yield os.path.join(root, f) diff --git a/tests/func/test_checkout.py b/tests/func/test_checkout.py index db02cdc58b..1f49ca4d84 100644 --- a/tests/func/test_checkout.py +++ b/tests/func/test_checkout.py @@ -18,7 +18,8 @@ from dvc.stage import StageFileBadNameError from dvc.stage import StageFileDoesNotExistError from dvc.system import System -from dvc.utils import relpath, walk_files +from dvc.utils import relpath +from dvc.utils.fs import walk_files from dvc.utils.stage import dump_stage_file from dvc.utils.stage import load_stage_file from tests.basic_env import TestDvc diff --git a/tests/unit/remote/test_remote_dir.py b/tests/unit/remote/test_remote_dir.py index b6d6c337b9..a39ef6981d 100644 --- a/tests/unit/remote/test_remote_dir.py +++ b/tests/unit/remote/test_remote_dir.py @@ -2,7 +2,7 @@ import pytest import os from dvc.remote.s3 import RemoteS3 -from dvc.utils import walk_files +from dvc.utils.fs import walk_files from dvc.path_info import PathInfo from tests.remotes import GCP, S3Mocked diff --git a/tests/unit/utils/test_fs.py b/tests/unit/utils/test_fs.py index 33ab5d342a..fbde5fcdf0 100644 --- a/tests/unit/utils/test_fs.py +++ b/tests/unit/utils/test_fs.py @@ -19,6 +19,7 @@ from dvc.utils.fs import move from dvc.utils.fs import path_isin, remove from dvc.utils.fs import makedirs +from dvc.utils.fs import walk_files from tests.basic_env import TestDir from tests.utils import spy @@ -244,3 +245,7 @@ def test_copyfile(path, repo_dir): ) else: assert filecmp.cmp(src_info.fspath, dest_info.fspath, shallow=False) + + +def test_walk_files(tmp_dir): + assert list(walk_files(".")) == list(walk_files(tmp_dir)) diff --git a/tests/unit/utils/test_utils.py b/tests/unit/utils/test_utils.py index 17870fe0bd..c4849ae307 100644 --- a/tests/unit/utils/test_utils.py +++ b/tests/unit/utils/test_utils.py @@ -9,7 +9,6 @@ from dvc.utils import relpath from dvc.utils import to_chunks from dvc.utils import tmp_fname -from dvc.utils import walk_files @pytest.mark.parametrize( @@ -105,7 +104,3 @@ def test_relpath(): path_info = PathInfo(path) assert relpath(path) == relpath(path_info) - - -def test_walk_files(tmp_dir): - assert list(walk_files(".")) == list(walk_files(tmp_dir))