From 9a88a412d067b2ee9dc58522107966f40d06378d Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Sun, 29 Apr 2018 17:40:27 +0300 Subject: [PATCH] dvc: reproduce stage if it has no dependencies and has cmd This allows as to define conditional stages in the dependency graph. Fixes #646 Fixes #648 Signed-off-by: Ruslan Kuprieiev --- dvc/stage.py | 4 ++++ tests/test_repro.py | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/dvc/stage.py b/dvc/stage.py index 96f806dac..bef7f9c78 100644 --- a/dvc/stage.py +++ b/dvc/stage.py @@ -92,6 +92,10 @@ class Stage(object): def changed(self): ret = False + + if not self.is_data_source and len(self.deps) == 0: + ret = True + for entry in itertools.chain(self.outs, self.deps): if entry.changed(): ret = True diff --git a/tests/test_repro.py b/tests/test_repro.py index 0fd9eb41b..9313faeb7 100644 --- a/tests/test_repro.py +++ b/tests/test_repro.py @@ -28,6 +28,22 @@ class TestRepro(TestDvc): cmd='python {} {} {}'.format(self.CODE, self.FOO, self.file1)) +class TestReproNoDeps(TestRepro): + def test(self): + out = 'out' + code_file = 'out.py' + stage_file = 'out.dvc' + code = 'import uuid\nwith open("{}", "w+") as fd:\n\tfd.write(str(uuid.uuid4()))\n'.format(out) + with open(code_file, 'w+') as fd: + fd.write(code) + self.dvc.run(fname=stage_file, + outs=[out], + cmd='python {}'.format(code_file)) + + stages = self.dvc.reproduce(stage_file) + self.assertEqual(len(stages), 1) + + class TestReproForce(TestRepro): def test(self): stages = self.dvc.reproduce(self.file1_stage, force=True)