Skip to content

Commit

Permalink
Merge pull request iterative#2277 from pared/1900
Browse files Browse the repository at this point in the history
reproduce: use kwargs instead of explicit arguments
  • Loading branch information
efiop authored Jul 18, 2019
2 parents 9b37c6b + 11cfd66 commit 598ef02
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 68 deletions.
79 changes: 16 additions & 63 deletions dvc/repo/reproduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
logger = logging.getLogger(__name__)


def _reproduce_stage(stages, node, force, dry, interactive, no_commit):
def _reproduce_stage(stages, node, **kwargs):
stage = stages[node]

if stage.locked:
Expand All @@ -19,13 +19,11 @@ def _reproduce_stage(stages, node, force, dry, interactive, no_commit):
" not going to be reproduced.".format(path=stage.relpath)
)

stage = stage.reproduce(
force=force, dry=dry, interactive=interactive, no_commit=no_commit
)
stage = stage.reproduce(**kwargs)
if not stage:
return []

if not dry:
if not kwargs.get("dry", False):
stage.dump()

return [stage]
Expand All @@ -35,27 +33,24 @@ def _reproduce_stage(stages, node, force, dry, interactive, no_commit):
def reproduce(
self,
target=None,
single_item=False,
force=False,
dry=False,
interactive=False,
recursive=False,
pipeline=False,
all_pipelines=False,
ignore_build_cache=False,
no_commit=False,
downstream=False,
recursive=False,
**kwargs
):
import networkx as nx
from dvc.stage import Stage

if not target and not all_pipelines:
raise ValueError()

interactive = kwargs.get("interactive", False)
if not interactive:
config = self.config
core = config.config[config.SECTION_CORE]
interactive = core.get(config.SECTION_CORE_INTERACTIVE, False)
kwargs["interactive"] = core.get(
config.SECTION_CORE_INTERACTIVE, False
)

targets = []
if recursive and os.path.isdir(target):
Expand All @@ -82,33 +77,13 @@ def reproduce(
ret = []
with self.state:
for target in targets:
stages = _reproduce(
self,
target,
single_item=single_item,
force=force,
dry=dry,
interactive=interactive,
ignore_build_cache=ignore_build_cache,
no_commit=no_commit,
downstream=downstream,
)
stages = _reproduce(self, target, **kwargs)
ret.extend(stages)

return ret


def _reproduce(
self,
target,
single_item=False,
force=False,
dry=False,
interactive=False,
ignore_build_cache=False,
no_commit=False,
downstream=False,
):
def _reproduce(self, target, single_item=False, **kwargs):
import networkx as nx
from dvc.stage import Stage

Expand All @@ -118,35 +93,15 @@ def _reproduce(
node = relpath(stage.path, self.root_dir)

if single_item:
ret = _reproduce_stage(
stages, node, force, dry, interactive, no_commit
)
ret = _reproduce_stage(stages, node, **kwargs)
else:
ret = _reproduce_stages(
G,
stages,
node,
force,
dry,
interactive,
ignore_build_cache,
no_commit,
downstream,
)
ret = _reproduce_stages(G, stages, node, **kwargs)

return ret


def _reproduce_stages(
G,
stages,
node,
force,
dry,
interactive,
ignore_build_cache,
no_commit,
downstream,
G, stages, node, downstream=False, ignore_build_cache=False, **kwargs
):
r"""Derive the evaluation of the given node for the given graph.
Expand Down Expand Up @@ -200,17 +155,15 @@ def _reproduce_stages(
result = []
for n in pipeline:
try:
ret = _reproduce_stage(
stages, n, force, dry, interactive, no_commit
)
ret = _reproduce_stage(stages, n, **kwargs)

if len(ret) != 0 and ignore_build_cache:
# NOTE: we are walking our pipeline from the top to the
# bottom. If one stage is changed, it will be reproduced,
# which tells us that we should force reproducing all of
# the other stages down below, even if their direct
# dependencies didn't change.
force = True
kwargs["force"] = True

result += ret
except Exception as ex:
Expand Down
9 changes: 4 additions & 5 deletions dvc/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,9 @@ def remove(self, force=False, remove_outs=True):
self.unprotect_outs()
os.unlink(self.path)

def reproduce(
self, force=False, dry=False, interactive=False, no_commit=False
):
if not force and not self.changed():
def reproduce(self, interactive=False, **kwargs):

if not kwargs.get("force", False) and not self.changed():
return None

msg = (
Expand All @@ -328,7 +327,7 @@ def reproduce(

logger.info("Reproducing '{stage}'".format(stage=self.relpath))

self.run(dry=dry, no_commit=no_commit, force=force)
self.run(**kwargs)

logger.debug("'{stage}' was reproduced".format(stage=self.relpath))

Expand Down

0 comments on commit 598ef02

Please sign in to comment.