From d80c43135f2b912e419ec9b715155ae80e057d37 Mon Sep 17 00:00:00 2001 From: Peter Rowlands Date: Mon, 7 Mar 2022 18:25:03 +0900 Subject: [PATCH] exp run: remove unsupported (repro only) arguments --- dvc/commands/experiments/run.py | 2 +- dvc/commands/repro.py | 59 +++++++++++++++----------- tests/unit/command/test_experiments.py | 2 +- tests/unit/command/test_repro.py | 17 +++++--- 4 files changed, 47 insertions(+), 33 deletions(-) diff --git a/dvc/commands/experiments/run.py b/dvc/commands/experiments/run.py index 374211d75..c71a799ae 100644 --- a/dvc/commands/experiments/run.py +++ b/dvc/commands/experiments/run.py @@ -39,7 +39,7 @@ class CmdExperimentsRun(CmdRepro): reset=self.args.reset, tmp_dir=self.args.tmp_dir, machine=self.args.machine, - **self._repro_kwargs, + **self._common_kwargs, ) if self.args.metrics and results: diff --git a/dvc/commands/repro.py b/dvc/commands/repro.py index eba1cb96c..362b20b68 100644 --- a/dvc/commands/repro.py +++ b/dvc/commands/repro.py @@ -10,7 +10,9 @@ class CmdRepro(CmdBase): def run(self): from dvc.ui import ui - stages = self.repo.reproduce(**self._repro_kwargs) + stages = self.repo.reproduce( + **self._common_kwargs, **self._repro_kwargs + ) if len(stages) == 0: ui.write(CmdDataStatus.UP_TO_DATE_MSG) else: @@ -27,7 +29,7 @@ class CmdRepro(CmdBase): return 0 @property - def _repro_kwargs(self): + def _common_kwargs(self): return { "targets": self.args.targets, "single_item": self.args.single_item, @@ -36,12 +38,17 @@ class CmdRepro(CmdBase): "interactive": self.args.interactive, "pipeline": self.args.pipeline, "all_pipelines": self.args.all_pipelines, - "run_cache": not self.args.no_run_cache, - "no_commit": self.args.no_commit, "downstream": self.args.downstream, "recursive": self.args.recursive, "force_downstream": self.args.force_downstream, "pull": self.args.pull, + } + + @property + def _repro_kwargs(self): + return { + "run_cache": not self.args.no_run_cache, + "no_commit": self.args.no_commit, "glob": self.args.glob, } @@ -110,15 +117,6 @@ def add_arguments(repro_parser): default=False, help="Reproduce all stages in the specified directory.", ) - repro_parser.add_argument( - "--no-run-cache", - action="store_true", - default=False, - help=( - "Execute stage commands even if they have already been run with " - "the same command/dependencies/outputs/etc before." - ), - ) repro_parser.add_argument( "--force-downstream", action="store_true", @@ -126,12 +124,6 @@ def add_arguments(repro_parser): help="Reproduce all descendants of a changed stage even if their " "direct dependencies didn't change.", ) - repro_parser.add_argument( - "--no-commit", - action="store_true", - default=False, - help="Don't put files/directories into cache.", - ) repro_parser.add_argument( "--downstream", action="store_true", @@ -147,12 +139,6 @@ def add_arguments(repro_parser): "from the run-cache." ), ) - repro_parser.add_argument( - "--glob", - action="store_true", - default=False, - help="Allows targets containing shell-style wildcards.", - ) def add_parser(subparsers, parent_parser): @@ -166,5 +152,28 @@ def add_parser(subparsers, parent_parser): help=REPRO_HELP, formatter_class=argparse.RawDescriptionHelpFormatter, ) + # repro/exp run shared args add_arguments(repro_parser) + # repro only args + repro_parser.add_argument( + "--no-run-cache", + action="store_true", + default=False, + help=( + "Execute stage commands even if they have already been run with " + "the same command/dependencies/outputs/etc before." + ), + ) + repro_parser.add_argument( + "--no-commit", + action="store_true", + default=False, + help="Don't put files/directories into cache.", + ) + repro_parser.add_argument( + "--glob", + action="store_true", + default=False, + help="Allows targets containing shell-style wildcards.", + ) repro_parser.set_defaults(func=CmdRepro) diff --git a/tests/unit/command/test_experiments.py b/tests/unit/command/test_experiments.py index 966070cfb..b9b57bd01 100644 --- a/tests/unit/command/test_experiments.py +++ b/tests/unit/command/test_experiments.py @@ -22,7 +22,7 @@ from dvc.stage import PipelineStage from tests.utils import ANY from tests.utils.asserts import called_once_with_subset -from .test_repro import default_arguments as repro_arguments +from .test_repro import common_arguments as repro_arguments def test_experiments_apply(dvc, scm, mocker): diff --git a/tests/unit/command/test_repro.py b/tests/unit/command/test_repro.py index 35f387e3f..fb213db73 100644 --- a/tests/unit/command/test_repro.py +++ b/tests/unit/command/test_repro.py @@ -1,22 +1,24 @@ from dvc.cli import parse_args from dvc.commands.repro import CmdRepro -default_arguments = { +common_arguments = { "all_pipelines": False, "downstream": False, "dry": False, "force": False, - "run_cache": True, "interactive": False, - "no_commit": False, "pipeline": False, "single_item": False, "recursive": False, "force_downstream": False, "pull": False, - "glob": False, "targets": [], } +repro_arguments = { + "run_cache": True, + "no_commit": False, + "glob": False, +} def test_default_arguments(dvc, mocker): @@ -24,14 +26,17 @@ def test_default_arguments(dvc, mocker): mocker.patch.object(cmd.repo, "reproduce") cmd.run() # pylint: disable=no-member - cmd.repo.reproduce.assert_called_with(**default_arguments) + cmd.repo.reproduce.assert_called_with( + **common_arguments, **repro_arguments + ) def test_downstream(dvc, mocker): cmd = CmdRepro(parse_args(["repro", "--downstream"])) mocker.patch.object(cmd.repo, "reproduce") cmd.run() - arguments = default_arguments.copy() + arguments = common_arguments.copy() + arguments.update(repro_arguments) arguments.update({"downstream": True}) # pylint: disable=no-member cmd.repo.reproduce.assert_called_with(**arguments)