diff --git a/dvc/cli.py b/dvc/cli.py index 63eab0292..1f9281e59 100644 --- a/dvc/cli.py +++ b/dvc/cli.py @@ -194,10 +194,10 @@ def parse_args(argv=None): remove_parser = subparsers.add_parser( 'remove', parents=[parent_parser], - help='Remove data file or data directory') + help='Remove outputs of DVC file.') remove_parser.add_argument('targets', nargs='+', - help='Target to remove - file or directory.') + help='DVC files.') remove_parser.set_defaults(func=CmdRemove) # Garbage collector diff --git a/dvc/project.py b/dvc/project.py index 2df906b8c..9d6d486ca 100644 --- a/dvc/project.py +++ b/dvc/project.py @@ -91,21 +91,15 @@ class Project(object): stage.dump() return stage - def remove(self, fname): - stages = [] - output = Output.loads(self, fname) - for out in self.outs(): - if out.path == output.path: - stage = out.stage() - stages.append(stage) + def remove(self, target): + if not Stage.is_stage_file(target): + raise StageNotFoundError(target) - if len(stages) == 0: - raise StageNotFoundError(fname) + stage = Stage.load(self, target) + for out in stage.outs: + out.remove() - for stage in stages: - stage.remove() - - return stages + return stage def run(self, cmd=None, diff --git a/tests/test_remove.py b/tests/test_remove.py index 2de7fa4cb..9934ec174 100644 --- a/tests/test_remove.py +++ b/tests/test_remove.py @@ -12,43 +12,35 @@ from tests.basic_env import TestDvc class TestRemove(TestDvc): def test(self): stage = self.dvc.add(self.FOO) - stages_removed = self.dvc.remove(self.FOO) + stage_removed = self.dvc.remove(stage.path) - self.assertEqual(len(stages_removed), 1) - self.assertIsInstance(stages_removed[0], Stage) - self.assertEqual(stage.path, stages_removed[0].path) + self.assertIsInstance(stage_removed, Stage) + self.assertEqual(stage.path, stage_removed.path) + self.assertFalse(os.path.isfile(self.FOO)) class TestRemoveNonExistentFile(TestDvc): def test(self): with self.assertRaises(StageNotFoundError) as cx: - self.dvc.remove('non_existent_file') - - -class TestRemoveFileOutsideOfRepo(TestDvc): - def test(self): - with self.assertRaises(CmdOutputOutsideOfRepoError) as cx: - self.dvc.remove(os.path.join(os.path.dirname(self.dvc.root_dir), self.FOO)) + self.dvc.remove('non_existent_dvc_file') class TestRemoveDirectory(TestDvc): def test(self): stage_add = self.dvc.add(self.DATA_DIR) - stages_removed = self.dvc.remove(self.DATA_DIR) - self.assertEqual(len(stages_removed), 1) - stage_removed = stages_removed[0] + stage_removed = self.dvc.remove(stage_add.path) self.assertEqual(stage_add.path, stage_removed.path) self.assertFalse(os.path.exists(self.DATA_DIR)) - self.assertFalse(os.path.exists(stage_removed.path)) + self.assertTrue(os.path.exists(stage_removed.path)) class TestCmdRemove(TestDvc): def test(self): - self.dvc.add(self.FOO) + stage = self.dvc.add(self.FOO) ret = main(['remove', - self.FOO]) + stage.path]) self.assertEqual(ret, 0) ret = main(['remove', - 'non-existing-file']) + 'non-existing-dvc-file']) self.assertNotEqual(ret, 0)