remove: force remove to remove persistent outputs

This commit is contained in:
pared
2019-03-26 11:41:12 +01:00
parent 2776f2f317
commit 70b804307d
3 changed files with 22 additions and 6 deletions
+2 -2
View File
@@ -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
+4 -4
View File
@@ -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(
+16
View File
@@ -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