diff --git a/dvc/repo/remove.py b/dvc/repo/remove.py index 2977ee82c..80792e497 100644 --- a/dvc/repo/remove.py +++ b/dvc/repo/remove.py @@ -3,8 +3,8 @@ def remove(self, target, outs_only=False): stage = Stage.load(self, target) if outs_only: - stage.remove_outs() + stage.remove_outs(force=True) else: - stage.remove() + stage.remove(force=True) return stage diff --git a/dvc/stage.py b/dvc/stage.py index ca338bd68..0a6f9ccc8 100644 --- a/dvc/stage.py +++ b/dvc/stage.py @@ -259,10 +259,10 @@ class Stage(object): return ret - def remove_outs(self, ignore_remove=False): + def remove_outs(self, ignore_remove=False, force=False): """Used mainly for `dvc remove --outs` and :func:`Stage.reproduce`.""" for out in self.outs: - if out.persist: + if out.persist and not force: out.unprotect() else: logger.debug( @@ -276,8 +276,8 @@ class Stage(object): for out in self.outs: out.unprotect() - def remove(self): - self.remove_outs(ignore_remove=True) + def remove(self, force=False): + self.remove_outs(ignore_remove=True, force=force) os.unlink(self.path) def reproduce( diff --git a/tests/test_run.py b/tests/test_run.py index 86ae2f0dd..5b0694abc 100644 --- a/tests/test_run.py +++ b/tests/test_run.py @@ -777,6 +777,14 @@ class TestRunPersist(TestDvc): file_content = "content" stage_file = file + Stage.STAGE_FILE_SUFFIX + self.run_command(file, file_content) + self.stage_should_contain_persist_flag(stage_file) + + self.should_append_upon_repro(file, stage_file) + + self.should_remove_persistent_outs(file, stage_file) + + def run_command(self, file, file_content): ret = main( [ "run", @@ -787,11 +795,13 @@ class TestRunPersist(TestDvc): ) self.assertEqual(0, ret) + def stage_should_contain_persist_flag(self, stage_file): stage_file_content = load_stage_file(stage_file) self.assertEqual( True, stage_file_content["outs"][0][OutputBase.PARAM_PERSIST] ) + def should_append_upon_repro(self, file, stage_file): ret = main(["repro", stage_file]) self.assertEqual(0, ret) @@ -799,6 +809,12 @@ class TestRunPersist(TestDvc): lines = fobj.readlines() self.assertEqual(2, len(lines)) + def should_remove_persistent_outs(self, file, stage_file): + ret = main(["remove", stage_file]) + self.assertEqual(0, ret) + + self.assertFalse(os.path.exists(file)) + class TestRunPersistOuts(TestRunPersist): @property