Skip to content

Commit fcca636

Browse files
Outputs as target supporting for dvc status (#4433)
* Outputs as target supporting for `dvc status` fix #4191 1. Add a related test which would fail on current version. * Pass the tests 1. add deps to the tests. 2. make change to pass the tests. * Update tests/func/test_status.py Co-authored-by: Saugat Pachhai <[email protected]> * Solve some change request. Co-authored-by: Saugat Pachhai <[email protected]>
1 parent 714503a commit fcca636

File tree

3 files changed

+36
-16
lines changed

3 files changed

+36
-16
lines changed

dvc/repo/status.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,32 @@
1010
logger = logging.getLogger(__name__)
1111

1212

13-
def _joint_status(stages):
13+
def _joint_status(pairs):
1414
status_info = {}
1515

16-
for stage in stages:
16+
for stage, filter_info in pairs:
1717
if stage.frozen and not stage.is_repo_import:
1818
logger.warning(
1919
"{} is frozen. Its dependencies are"
2020
" not going to be shown in the status output.".format(stage)
2121
)
22-
23-
status_info.update(stage.status(check_updates=True))
22+
if not filter_info:
23+
status_info.update(stage.status(check_updates=True))
24+
else:
25+
for out in stage.filter_outs(filter_info):
26+
status_info.update(out.status())
2427

2528
return status_info
2629

2730

2831
def _local_status(self, targets=None, with_deps=False, recursive=False):
29-
if targets:
30-
stages = cat(
31-
self.collect(t, with_deps=with_deps, recursive=recursive)
32-
for t in targets
33-
)
34-
else:
35-
stages = self.collect(None, with_deps=with_deps, recursive=recursive)
32+
targets = targets or [None]
33+
pairs = cat(
34+
self.collect_granular(t, with_deps=with_deps, recursive=recursive)
35+
for t in targets
36+
)
3637

37-
return _joint_status(stages)
38+
return _joint_status(pairs)
3839

3940

4041
def _cloud_status(

dvc/stage/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ def run(self, dry=False, no_commit=False, force=False, run_cache=True):
442442
if not no_commit:
443443
self.commit()
444444

445-
def _filter_outs(self, path_info):
445+
def filter_outs(self, path_info):
446446
def _func(o):
447447
return path_info.isin_or_eq(o.path_info)
448448

@@ -451,7 +451,7 @@ def _func(o):
451451
@rwlocked(write=["outs"])
452452
def checkout(self, **kwargs):
453453
stats = defaultdict(list)
454-
for out in self._filter_outs(kwargs.get("filter_info")):
454+
for out in self.filter_outs(kwargs.get("filter_info")):
455455
key, outs = self._checkout(out, **kwargs)
456456
if key:
457457
stats[key].extend(outs)
@@ -526,14 +526,14 @@ def outs_cached(self):
526526
def get_all_files_number(self, filter_info=None):
527527
return sum(
528528
out.get_files_number(filter_info)
529-
for out in self._filter_outs(filter_info)
529+
for out in self.filter_outs(filter_info)
530530
)
531531

532532
def get_used_cache(self, *args, **kwargs):
533533
from dvc.cache import NamedCache
534534

535535
cache = NamedCache()
536-
for out in self._filter_outs(kwargs.get("filter_info")):
536+
for out in self.filter_outs(kwargs.get("filter_info")):
537537
cache.update(out.get_used_cache(*args, **kwargs))
538538

539539
return cache

tests/func/test_status.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,22 @@ def test_status_recursive(tmp_dir, dvc):
118118
}
119119
],
120120
}
121+
122+
123+
def test_status_outputs(tmp_dir, dvc):
124+
tmp_dir.dvc_gen({"foo": "foo", "bar": "bar"})
125+
dvc.run(
126+
outs=["alice", "bob"],
127+
deps=["foo", "bar"],
128+
cmd="echo alice>alice && echo bob>bob",
129+
name="alice_bob",
130+
)
131+
tmp_dir.gen({"alice": "new alice", "bob": "new bob"})
132+
133+
assert dvc.status(targets=["alice_bob"]) == {
134+
"alice_bob": [
135+
{"changed outs": {"alice": "modified", "bob": "modified"}}
136+
]
137+
}
138+
139+
assert dvc.status(targets=["alice"]) == {"alice": "modified"}

0 commit comments

Comments
 (0)