Skip to content

Commit

Permalink
push/pull/status/metrics: add support for --all-commits (iterative#…
Browse files Browse the repository at this point in the history
…3587)

First steps for iterative#1691
  • Loading branch information
efiop authored Apr 4, 2020
1 parent b9d560c commit 7bd4733
Show file tree
Hide file tree
Showing 11 changed files with 250 additions and 7 deletions.
28 changes: 28 additions & 0 deletions dvc/command/data_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def run(self):
remote=self.args.remote,
all_branches=self.args.all_branches,
all_tags=self.args.all_tags,
all_commits=self.args.all_commits,
with_deps=self.args.with_deps,
force=self.args.force,
recursive=self.args.recursive,
Expand All @@ -49,6 +50,7 @@ def run(self):
remote=self.args.remote,
all_branches=self.args.all_branches,
all_tags=self.args.all_tags,
all_commits=self.args.all_commits,
with_deps=self.args.with_deps,
recursive=self.args.recursive,
)
Expand All @@ -68,6 +70,7 @@ def run(self):
remote=self.args.remote,
all_branches=self.args.all_branches,
all_tags=self.args.all_tags,
all_commits=self.args.all_commits,
with_deps=self.args.with_deps,
recursive=self.args.recursive,
)
Expand Down Expand Up @@ -128,6 +131,12 @@ def add_parser(subparsers, _parent_parser):
default=False,
help="Fetch cache for all tags.",
)
pull_parser.add_argument(
"--all-commits",
action="store_true",
default=False,
help="Fetch cache for all commits.",
)
pull_parser.add_argument(
"-f",
"--force",
Expand Down Expand Up @@ -178,6 +187,12 @@ def add_parser(subparsers, _parent_parser):
default=False,
help="Push cache for all tags.",
)
push_parser.add_argument(
"--all-commits",
action="store_true",
default=False,
help="Push cache for all commits.",
)
push_parser.add_argument(
"-d",
"--with-deps",
Expand Down Expand Up @@ -224,6 +239,12 @@ def add_parser(subparsers, _parent_parser):
default=False,
help="Fetch cache for all tags.",
)
fetch_parser.add_argument(
"--all-commits",
action="store_true",
default=False,
help="Fetch cache for all commits.",
)
fetch_parser.add_argument(
"-d",
"--with-deps",
Expand Down Expand Up @@ -289,6 +310,13 @@ def add_parser(subparsers, _parent_parser):
help="Show status of a local cache compared to a remote repository "
"for all tags.",
)
status_parser.add_argument(
"--all-commits",
action="store_true",
default=False,
help="Show status of a local cache compared to a remote repository "
"for all commits.",
)
status_parser.add_argument(
"-d",
"--with-deps",
Expand Down
20 changes: 17 additions & 3 deletions dvc/command/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
logger = logging.getLogger(__name__)


def show_metrics(metrics, all_branches=False, all_tags=False):
def show_metrics(
metrics, all_branches=False, all_tags=False, all_commits=False
):
"""
Args:
metrics (list): Where each element is either a `list`
Expand All @@ -22,7 +24,7 @@ def show_metrics(metrics, all_branches=False, all_tags=False):
missing = metrics.pop(None, None)

for branch, val in metrics.items():
if all_branches or all_tags:
if all_branches or all_tags or all_commits:
logger.info("{branch}:".format(branch=branch))

for fname, metric in val.items():
Expand Down Expand Up @@ -55,10 +57,16 @@ def run(self):
xpath=self.args.xpath,
all_branches=self.args.all_branches,
all_tags=self.args.all_tags,
all_commits=self.args.all_commits,
recursive=self.args.recursive,
)

show_metrics(metrics, self.args.all_branches, self.args.all_tags)
show_metrics(
metrics,
self.args.all_branches,
self.args.all_tags,
self.args.all_commits,
)
except DvcException:
logger.exception("failed to show metrics")
return 1
Expand Down Expand Up @@ -215,6 +223,12 @@ def add_parser(subparsers, parent_parser):
default=False,
help="Show metrics for all tags.",
)
metrics_show_parser.add_argument(
"--all-commits",
action="store_true",
default=False,
help="Show metrics for all commits.",
)
metrics_show_parser.add_argument(
"-R",
"--recursive",
Expand Down
1 change: 1 addition & 0 deletions dvc/command/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def run(self):
remote=self.args.remote,
all_branches=self.args.all_branches,
all_tags=self.args.all_tags,
all_commits=self.args.all_commits,
with_deps=self.args.with_deps,
)
if st:
Expand Down
2 changes: 2 additions & 0 deletions dvc/repo/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def _fetch(
with_deps=False,
all_tags=False,
recursive=False,
all_commits=False,
):
"""Download data items from a cloud and imported repositories
Expand All @@ -37,6 +38,7 @@ def _fetch(
targets,
all_branches=all_branches,
all_tags=all_tags,
all_commits=all_commits,
with_deps=with_deps,
force=True,
remote=remote,
Expand Down
6 changes: 5 additions & 1 deletion dvc/repo/metrics/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ def show(
all_tags=False,
recursive=False,
revs=None,
all_commits=False,
):
res = {}
found = set()
Expand All @@ -276,7 +277,10 @@ def show(
targets = [None]

for branch in repo.brancher(
revs=revs, all_branches=all_branches, all_tags=all_tags
revs=revs,
all_branches=all_branches,
all_tags=all_tags,
all_commits=all_commits,
):
metrics = {}

Expand Down
2 changes: 2 additions & 0 deletions dvc/repo/pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ def pull(
all_tags=False,
force=False,
recursive=False,
all_commits=False,
):
processed_files_count = self._fetch(
targets,
jobs,
remote=remote,
all_branches=all_branches,
all_tags=all_tags,
all_commits=all_commits,
with_deps=with_deps,
recursive=recursive,
)
Expand Down
2 changes: 2 additions & 0 deletions dvc/repo/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ def push(
with_deps=False,
all_tags=False,
recursive=False,
all_commits=False,
):
used = self.used_cache(
targets,
all_branches=all_branches,
all_tags=all_tags,
all_commits=all_commits,
with_deps=with_deps,
force=True,
remote=remote,
Expand Down
8 changes: 6 additions & 2 deletions dvc/repo/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def _cloud_status(
all_branches=False,
with_deps=False,
all_tags=False,
all_commits=False,
):
"""Returns a dictionary with the files that are new or deleted.
Expand Down Expand Up @@ -77,6 +78,7 @@ def _cloud_status(
targets,
all_branches=all_branches,
all_tags=all_tags,
all_commits=all_commits,
with_deps=with_deps,
force=True,
remote=remote,
Expand Down Expand Up @@ -108,6 +110,7 @@ def status(
all_branches=False,
with_deps=False,
all_tags=False,
all_commits=False,
):
if cloud or remote:
return _cloud_status(
Expand All @@ -118,12 +121,13 @@ def status(
with_deps=with_deps,
remote=remote,
all_tags=all_tags,
all_commits=all_commits,
)

ignored = list(
compress(
["--all-branches", "--all-tags", "--jobs"],
[all_branches, all_tags, jobs],
["--all-branches", "--all-tags", "--all-commits", "--jobs"],
[all_branches, all_tags, all_commits, jobs],
)
)
if ignored:
Expand Down
112 changes: 112 additions & 0 deletions tests/unit/command/test_data_sync.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
from dvc.cli import parse_args
from dvc.command.data_sync import CmdDataFetch, CmdDataPull, CmdDataPush


def test_fetch(mocker):
cli_args = parse_args(
[
"fetch",
"target1",
"target2",
"--jobs",
"2",
"--remote",
"remote",
"--all-branches",
"--all-tags",
"--all-commits",
"--with-deps",
"--recursive",
]
)
assert cli_args.func == CmdDataFetch

cmd = cli_args.func(cli_args)
m = mocker.patch.object(cmd.repo, "fetch", autospec=True)

assert cmd.run() == 0

m.assert_called_once_with(
targets=["target1", "target2"],
jobs=2,
remote="remote",
all_branches=True,
all_tags=True,
all_commits=True,
with_deps=True,
recursive=True,
)


def test_pull(mocker):
cli_args = parse_args(
[
"pull",
"target1",
"target2",
"--jobs",
"2",
"--remote",
"remote",
"--all-branches",
"--all-tags",
"--all-commits",
"--with-deps",
"--force",
"--recursive",
]
)
assert cli_args.func == CmdDataPull

cmd = cli_args.func(cli_args)
m = mocker.patch.object(cmd.repo, "pull", autospec=True)

assert cmd.run() == 0

m.assert_called_once_with(
targets=["target1", "target2"],
jobs=2,
remote="remote",
all_branches=True,
all_tags=True,
all_commits=True,
with_deps=True,
force=True,
recursive=True,
)


def test_push(mocker):
cli_args = parse_args(
[
"push",
"target1",
"target2",
"--jobs",
"2",
"--remote",
"remote",
"--all-branches",
"--all-tags",
"--all-commits",
"--with-deps",
"--recursive",
]
)
assert cli_args.func == CmdDataPush

cmd = cli_args.func(cli_args)
m = mocker.patch.object(cmd.repo, "push", autospec=True)

assert cmd.run() == 0

m.assert_called_once_with(
targets=["target1", "target2"],
jobs=2,
remote="remote",
all_branches=True,
all_tags=True,
all_commits=True,
with_deps=True,
recursive=True,
)
Loading

0 comments on commit 7bd4733

Please sign in to comment.