Skip to content

Commit

Permalink
review v2
Browse files Browse the repository at this point in the history
  • Loading branch information
pared committed Dec 30, 2020
1 parent 47d1c0a commit bbe180f
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 37 deletions.
35 changes: 17 additions & 18 deletions dvc/command/live.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,25 @@ def run(self):
return self._run(self.args.target, self.args.revs)


def shared_parent_parser():
parent_parser = argparse.ArgumentParser(add_help=False)
parent_parser.add_argument(
"target", help="Logs dir to produce summary from",
).complete = completion.DIR
parent_parser.add_argument(
"-o",
"--out",
default=None,
help="Destination path to save plots to",
metavar="<path>",
).complete = completion.DIR
return parent_parser


def add_parser(subparsers, parent_parser):
LIVE_DESCRIPTION = (
"Commands to visualize and compare dvclive-produced logs."
)

live_parser = subparsers.add_parser(
"live",
parents=[parent_parser],
Expand All @@ -54,11 +68,10 @@ def add_parser(subparsers, parent_parser):
SHOW_HELP = "Visualize dvclive directory content."
live_show_parser = live_subparsers.add_parser(
"show",
parents=[parent_parser],
parents=[parent_parser, shared_parent_parser()],
help=SHOW_HELP,
formatter_class=argparse.RawDescriptionHelpFormatter,
)
_add_common_arguments(live_show_parser)
live_show_parser.set_defaults(func=CmdLiveShow)

DIFF_HELP = (
Expand All @@ -67,7 +80,7 @@ def add_parser(subparsers, parent_parser):
)
live_diff_parser = live_subparsers.add_parser(
"diff",
parents=[parent_parser],
parents=[parent_parser, shared_parent_parser()],
help=DIFF_HELP,
formatter_class=argparse.RawDescriptionHelpFormatter,
)
Expand All @@ -78,18 +91,4 @@ def add_parser(subparsers, parent_parser):
help="Git revision (e.g. SHA, branch, tag)",
metavar="<commit>",
)
_add_common_arguments(live_diff_parser)
live_diff_parser.set_defaults(func=CmdLiveDiff)


def _add_common_arguments(parser):
parser.add_argument(
"target", help="Logs dir to produce summary from",
).complete = completion.DIR
parser.add_argument(
"-o",
"--out",
default=None,
help="Destination path to save plots to",
metavar="<path>",
).complete = completion.DIR
12 changes: 4 additions & 8 deletions dvc/command/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def run(self):
metrics_no_cache=self.args.metrics_no_cache,
plots=self.args.plots,
plots_no_cache=self.args.plots_no_cache,
live=self.args.dvclive,
live_summary=not self.args.dvclive_no_summary,
live=self.args.live,
live_summary=not self.args.live_no_summary,
deps=self.args.deps,
params=self.args.params,
fname=self.args.file,
Expand Down Expand Up @@ -165,14 +165,10 @@ def add_parser(subparsers, parent_parser):
metavar="<path>",
)
run_parser.add_argument(
"--dvclive",
action="append",
default=[],
help=argparse.SUPPRESS,
metavar="<path>",
"--live", help=argparse.SUPPRESS, metavar="<path>",
)
run_parser.add_argument(
"--dvclive-no-summary",
"--live-no-summary",
action="store_true",
default=False,
help=argparse.SUPPRESS,
Expand Down
4 changes: 2 additions & 2 deletions dvc/repo/run.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
from contextlib import suppress

from funcy import concat, first, lfilter
from funcy import concat, first, lfilter, without

from dvc.exceptions import InvalidArgumentError
from dvc.stage import PipelineStage
Expand Down Expand Up @@ -49,7 +49,7 @@ def _get_file_path(kwargs):
kwargs.get("outs_persist", []),
kwargs.get("outs_persist_no_cache", []),
kwargs.get("checkpoints", []),
kwargs.get("live", []),
without([kwargs.get("live", None)], None),
)
)

Expand Down
4 changes: 2 additions & 2 deletions dvc/stage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ def is_checkpoint(self):
def env(self) -> Dict[str, str]:
env = {}
for out in self.outs:
if any(out.environment.keys() and env.keys()):
if any(out.env.keys() and env.keys()):
raise DvcException("Duplicated env variable")
env.update(out.environment)
env.update(out.env)
return env

def changed_deps(self):
Expand Down
2 changes: 1 addition & 1 deletion dvc/stage/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def prepare_kwargs(stage, checkpoint_func=None):
# indicate that checkpoint cmd is being run inside DVC
kwargs["env"].update(_checkpoint_env(stage))

kwargs["env"].update(stage.environment)
kwargs["env"].update(stage.env)

# NOTE: when you specify `shell=True`, `Popen` [1] will default to
# `/bin/sh` on *nix and will add ["/bin/sh", "-c"] to your command.
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/command/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ def test_run(mocker, dvc):
"plots",
"--plots-no-cache",
"plots-no-cache",
"--dvclive",
"dvclive",
"--dvclive-no-summary",
"--live",
"live",
"--live-no-summary",
"--file",
"file",
"--wdir",
Expand Down Expand Up @@ -69,7 +69,7 @@ def test_run(mocker, dvc):
outs_persist_no_cache=["outs-persist-no-cache"],
checkpoints=["checkpoints"],
params=["file:param1,param2", "param3"],
live=["dvclive"],
live="live",
live_summary=False,
fname="file",
wdir="wdir",
Expand Down Expand Up @@ -99,7 +99,7 @@ def test_run_args_from_cli(mocker, dvc):
metrics_no_cache=[],
plots=[],
plots_no_cache=[],
live=[],
live=None,
live_summary=True,
outs_persist=[],
outs_persist_no_cache=[],
Expand Down Expand Up @@ -133,7 +133,7 @@ def test_run_args_with_spaces(mocker, dvc):
metrics_no_cache=[],
plots=[],
plots_no_cache=[],
live=[],
live=None,
live_summary=True,
outs_persist=[],
outs_persist_no_cache=[],
Expand Down

0 comments on commit bbe180f

Please sign in to comment.