Skip to content

Commit 594716e

Browse files
authored
status: add option to skip imports (#10277)
1 parent 84b2e68 commit 594716e

File tree

5 files changed

+60
-10
lines changed

5 files changed

+60
-10
lines changed

dvc/commands/data_sync.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,5 +429,11 @@ def add_parser(subparsers, _parent_parser):
429429
default=False,
430430
help="Show status in JSON format.",
431431
)
432+
status_parser.add_argument(
433+
"--no-updates",
434+
dest="check_updates",
435+
action="store_false",
436+
help="Ignore updates to imported data.",
437+
)
432438

433439
status_parser.set_defaults(func=CmdDataStatus)

dvc/commands/status.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def run(self):
6060
all_commits=self.args.all_commits,
6161
with_deps=self.args.with_deps,
6262
recursive=self.args.recursive,
63+
check_updates=self.args.check_updates,
6364
)
6465
except DvcException:
6566
logger.exception("")

dvc/repo/status.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
logger = logger.getChild(__name__)
99

1010

11-
def _joint_status(pairs):
11+
def _joint_status(pairs, check_updates=True):
1212
status_info = {}
1313

1414
for stage, filter_info in pairs:
@@ -20,19 +20,23 @@ def _joint_status(pairs):
2020
),
2121
stage,
2222
)
23-
status_info.update(stage.status(check_updates=True, filter_info=filter_info))
23+
status_info.update(
24+
stage.status(check_updates=check_updates, filter_info=filter_info)
25+
)
2426

2527
return status_info
2628

2729

28-
def _local_status(self, targets=None, with_deps=False, recursive=False):
30+
def _local_status(
31+
self, targets=None, with_deps=False, recursive=False, check_updates=True
32+
):
2933
targets = targets or [None]
3034
pairs = chain.from_iterable(
3135
self.stage.collect_granular(t, with_deps=with_deps, recursive=recursive)
3236
for t in targets
3337
)
3438

35-
return _joint_status(pairs)
39+
return _joint_status(pairs, check_updates=check_updates)
3640

3741

3842
def _cloud_status(
@@ -100,7 +104,7 @@ def _cloud_status(
100104

101105

102106
@locked
103-
def status(
107+
def status( # noqa: PLR0913
104108
self,
105109
targets=None,
106110
jobs=None,
@@ -111,6 +115,7 @@ def status(
111115
all_tags=False,
112116
all_commits=False,
113117
recursive=False,
118+
check_updates=True,
114119
):
115120
if isinstance(targets, str):
116121
targets = [targets]
@@ -138,4 +143,10 @@ def status(
138143
msg = "The following options are meaningless for local status: {}"
139144
raise InvalidArgumentError(msg.format(", ".join(ignored)))
140145

141-
return _local_status(self, targets, with_deps=with_deps, recursive=recursive)
146+
return _local_status(
147+
self,
148+
targets,
149+
with_deps=with_deps,
150+
recursive=recursive,
151+
check_updates=check_updates,
152+
)

tests/func/test_status.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import os
22

3+
import pytest
4+
35
from dvc.cli import main
46
from dvc.fs import localfs
57

@@ -30,19 +32,25 @@ def test_implied_cloud(dvc, mocker):
3032
assert mock_status.called
3133

3234

33-
def test_status_non_dvc_repo_import(tmp_dir, dvc, git_dir):
35+
@pytest.mark.parametrize("check_updates", [True, False])
36+
def test_status_non_dvc_repo_import(tmp_dir, dvc, git_dir, check_updates):
3437
with git_dir.branch("branch", new=True):
3538
git_dir.scm_gen("file", "first version", commit="first version")
3639

3740
dvc.imp(os.fspath(git_dir), "file", "file", rev="branch")
3841

39-
assert dvc.status(["file.dvc"]) == {}
42+
assert dvc.status(["file.dvc"], check_updates=check_updates) == {}
4043

4144
with git_dir.branch("branch", new=False):
4245
git_dir.scm_gen("file", "second version", commit="update file")
4346

44-
(status,) = dvc.status(["file.dvc"])["file.dvc"]
45-
assert status == {"changed deps": {f"file ({git_dir})": "update available"}}
47+
status = dvc.status(["file.dvc"], check_updates=check_updates)
48+
if check_updates:
49+
assert status == {
50+
"file.dvc": [{"changed deps": {f"file ({git_dir})": "update available"}}]
51+
}
52+
else:
53+
assert status == {}
4654

4755

4856
def test_status_before_and_after_dvc_init(tmp_dir, dvc, git_dir):

tests/unit/command/test_status.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def test_cloud_status(tmp_dir, dvc, mocker):
4141
all_commits=True,
4242
with_deps=True,
4343
recursive=True,
44+
check_updates=True,
4445
)
4546

4647

@@ -117,3 +118,26 @@ def test_status_up_to_date(dvc, mocker, capsys, cloud_opts, expected_message):
117118
assert cmd.run() == 0
118119
captured = capsys.readouterr()
119120
assert expected_message in captured.out
121+
122+
123+
def test_status_check_updates(dvc, mocker, capsys):
124+
cli_args = parse_args(["status", "--no-updates"])
125+
assert cli_args.func == CmdDataStatus
126+
127+
cmd = cli_args.func(cli_args)
128+
m = mocker.patch.object(cmd.repo, "status", autospec=True, return_value={})
129+
130+
assert cmd.run() == 0
131+
132+
m.assert_called_once_with(
133+
cloud=False,
134+
targets=[],
135+
jobs=None,
136+
remote=None,
137+
all_branches=False,
138+
all_tags=False,
139+
all_commits=False,
140+
with_deps=False,
141+
recursive=False,
142+
check_updates=False,
143+
)

0 commit comments

Comments
 (0)