Skip to content

Commit

Permalink
Merge pull request #3048 from Suor/optimize-stages
Browse files Browse the repository at this point in the history
dvc: optimize and clean up stages collection
  • Loading branch information
efiop authored Jan 3, 2020
2 parents bdcc995 + b2d083f commit 85c35f8
Showing 1 changed file with 5 additions and 15 deletions.
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

0 comments on commit 85c35f8

Please sign in to comment.