Skip to content
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

dvc: optimize and clean up stages collection #3048

Merged
merged 1 commit into from
Jan 3, 2020
Merged
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
20 changes: 5 additions & 15 deletions dvc/repo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,17 +363,6 @@ def graph(self):
def pipelines(self):
return get_pipelines(self.graph)

@staticmethod
def _filter_out_dirs(dirs, outs, root_dir):
def filter_dirs(dname):
path = os.path.join(root_dir, dname)
for out in outs:
if path == os.path.normpath(out):
return False
return True

return list(filter(filter_dirs, dirs))

@cached_property
def stages(self):
"""
Expand All @@ -388,20 +377,21 @@ def stages(self):
from dvc.stage import Stage

stages = []
outs = []
outs = set()

for root, dirs, files in self.tree.walk(self.root_dir):
for fname in files:
path = os.path.join(root, fname)
if not Stage.is_valid_filename(path):
continue
stage = Stage.load(self, path)
stages.append(stage)

for out in stage.outs:
if out.scheme == "local":
outs.append(out.fspath + out.sep)
stages.append(stage)
outs.add(out.fspath)

dirs[:] = self._filter_out_dirs(dirs, outs, root)
dirs[:] = [d for d in dirs if os.path.join(root, d) not in outs]

return stages

Expand Down