Skip to content

RFC: remote local, repo: use walk_files instead of os.walk #1750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions dvc/remote/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@
STATUS_DELETED,
STATUS_MISSING,
)
from dvc.utils import remove, move, copyfile, dict_md5, to_chunks, tmp_fname
from dvc.utils import (
remove,
move,
copyfile,
dict_md5,
to_chunks,
tmp_fname,
walk_files,
)
from dvc.utils import LARGE_DIR_SIZE
from dvc.config import Config
from dvc.exceptions import DvcException
Expand Down Expand Up @@ -353,11 +361,7 @@ def already_cached(self, path_info):
return not self.changed_cache(current_md5)

def _discard_working_directory_changes(self, path, dir_info, force=False):
working_dir_files = set(
os.path.join(root, file)
for root, _, files in os.walk(str(path))
for file in files
)
working_dir_files = set(path for path in walk_files(path))

cached_files = set(
os.path.join(path, file["relpath"]) for file in dir_info
Expand Down
8 changes: 3 additions & 5 deletions dvc/repo/unprotect.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import dvc.logger as logger
from dvc.system import System
from dvc.utils import copyfile, remove
from dvc.utils import copyfile, remove, walk_files
from dvc.exceptions import DvcException


Expand All @@ -33,10 +33,8 @@ def _unprotect_file(path):


def _unprotect_dir(path):
for root, dirs, files in os.walk(str(path)):
for f in files:
path = os.path.join(root, f)
_unprotect_file(path)
for path in walk_files(path):
_unprotect_file(path)


def unprotect(path):
Expand Down
2 changes: 1 addition & 1 deletion dvc/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,6 @@ def load_stage_file(path):


def walk_files(directory):
for root, _, files in os.walk(directory):
for root, _, files in os.walk(str(directory)):
for f in files:
yield os.path.join(root, f)
6 changes: 2 additions & 4 deletions tests/test_checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from dvc.main import main
from dvc.repo import Repo as DvcRepo
from dvc.system import System
from dvc.utils import walk_files
from tests.basic_env import TestDvc
from tests.test_repro import TestRepro
from dvc.stage import Stage
Expand Down Expand Up @@ -121,10 +122,7 @@ def outs_info(self, stage):
FileInfo = collections.namedtuple("FileInfo", "path inode")

paths = [
os.path.join(root, file)
for output in stage.outs
for root, _, files in os.walk(output.path)
for file in files
path for output in stage.outs for path in walk_files(output.path)
]

return [
Expand Down