mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-04 15:28:27 +01:00
dvc: replace StageNotFoundError with NotDvcFileError
Fixes #760 Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
+1
-12
@@ -1,7 +1,7 @@
|
||||
import os
|
||||
|
||||
from dvc.command.common.base import CmdBase
|
||||
from dvc.project import ReproductionError, StageNotFoundError
|
||||
from dvc.project import ReproductionError
|
||||
from dvc.stage import Stage
|
||||
|
||||
|
||||
@@ -23,17 +23,6 @@ class CmdRepro(CmdBase):
|
||||
self.project.logger.error(msg, ex)
|
||||
ret = 1
|
||||
break
|
||||
except StageNotFoundError as ex:
|
||||
if os.path.exists(target):
|
||||
msg = '\'{}\' is not a dvc file.'.format(target)
|
||||
dvcfile = target + Stage.STAGE_FILE_SUFFIX
|
||||
if os.path.exists(target) and os.path.isfile(dvcfile):
|
||||
msg += ' Maybe you meant \'{}\'?'.format(dvcfile)
|
||||
else:
|
||||
msg = '\'{}\' does not exist.'.format(target)
|
||||
self.project.logger.error(msg)
|
||||
ret = 1
|
||||
break
|
||||
except Exception as ex:
|
||||
msg = 'Failed to reproduce \'{}\' - unexpected error'.format(target)
|
||||
self.project.logger.error(msg, ex)
|
||||
|
||||
+10
-6
@@ -25,14 +25,18 @@ class InitError(DvcException):
|
||||
super(InitError, self).__init__(msg)
|
||||
|
||||
|
||||
class StageNotFoundError(DvcException):
|
||||
class NotDvcFileError(DvcException):
|
||||
def __init__(self, path):
|
||||
msg = 'Stage file {} does not exist'.format(path)
|
||||
super(StageNotFoundError, self).__init__(msg)
|
||||
msg = '\'{}\' is not a DVC file'.format(path)
|
||||
p = path + Stage.STAGE_FILE_SUFFIX
|
||||
if Stage.is_stage_file(p):
|
||||
msg += '. Maybe you meant \'{}\'?'.format(p)
|
||||
super(NotDvcFileError, self).__init__(msg)
|
||||
|
||||
|
||||
class ReproductionError(DvcException):
|
||||
def __init__(self, dvc_file_name, ex):
|
||||
self.path = dvc_file_name
|
||||
msg = 'Failed to reproduce \'{}\''.format(dvc_file_name)
|
||||
super(ReproductionError, self).__init__(msg, cause=ex)
|
||||
|
||||
@@ -125,7 +129,7 @@ class Project(object):
|
||||
|
||||
def remove(self, target, outs_only=False):
|
||||
if not Stage.is_stage_file(target):
|
||||
raise StageNotFoundError(target)
|
||||
raise NotDvcFileError(target)
|
||||
|
||||
stage = Stage.load(self, target)
|
||||
if outs_only:
|
||||
@@ -166,7 +170,7 @@ class Project(object):
|
||||
stages = nx.get_node_attributes(self.graph(), 'stage')
|
||||
node = os.path.relpath(os.path.abspath(target), self.root_dir)
|
||||
if node not in stages:
|
||||
raise StageNotFoundError(target)
|
||||
raise NotDvcFileError(target)
|
||||
|
||||
if recursive:
|
||||
return self._reproduce_stages(stages, node, force)
|
||||
@@ -185,7 +189,7 @@ class Project(object):
|
||||
def checkout(self, target=None):
|
||||
if target:
|
||||
if not Stage.is_stage_file(target):
|
||||
raise StageNotFoundError(target)
|
||||
raise NotDvcFileError(target)
|
||||
stages = [Stage.load(self, target)]
|
||||
else:
|
||||
self.link_state.remove_all()
|
||||
|
||||
@@ -8,7 +8,6 @@ from dvc.utils import file_md5
|
||||
from dvc.stage import Stage
|
||||
from dvc.output.base import OutputAlreadyTrackedError
|
||||
from dvc.output.base import OutputDoesNotExistError, OutputIsNotFileOrDirError
|
||||
from dvc.project import StageNotFoundError
|
||||
from dvc.command.add import CmdAdd
|
||||
|
||||
from tests.basic_env import TestDvc
|
||||
|
||||
@@ -5,7 +5,6 @@ import filecmp
|
||||
from dvc.main import main
|
||||
from dvc.utils import file_md5
|
||||
from dvc.stage import Stage
|
||||
from dvc.project import StageNotFoundError
|
||||
from dvc.command.gc import CmdGC
|
||||
|
||||
from tests.basic_env import TestDvc
|
||||
|
||||
@@ -2,7 +2,7 @@ import os
|
||||
|
||||
from dvc.main import main
|
||||
from dvc.stage import Stage
|
||||
from dvc.project import StageNotFoundError
|
||||
from dvc.project import NotDvcFileError
|
||||
from dvc.command.remove import CmdRemove
|
||||
|
||||
from tests.basic_env import TestDvc
|
||||
@@ -26,7 +26,7 @@ class TestRemove(TestDvc):
|
||||
|
||||
class TestRemoveNonExistentFile(TestDvc):
|
||||
def test(self):
|
||||
with self.assertRaises(StageNotFoundError) as cx:
|
||||
with self.assertRaises(NotDvcFileError) as cx:
|
||||
self.dvc.remove('non_existent_dvc_file')
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user