diff --git a/dvc/git_wrapper.py b/dvc/git_wrapper.py index 1dc896a50..ff9aae3f5 100644 --- a/dvc/git_wrapper.py +++ b/dvc/git_wrapper.py @@ -5,7 +5,8 @@ from dvc.config import Config from dvc.executor import Executor, ExecutorError from dvc.path.data_item import DataItemError from dvc.system import System -from dvc.workflow import Workflow, Commit +from dvc.graph.workflow import Workflow +from dvc.graph.commit import Commit class GitWrapperI(object): diff --git a/dvc/graph/__init__.py b/dvc/graph/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/dvc/graph/commit.py b/dvc/graph/commit.py new file mode 100644 index 000000000..736c2da1e --- /dev/null +++ b/dvc/graph/commit.py @@ -0,0 +1,59 @@ +class Commit(object): + TEXT_LIMIT = 30 + DVC_REPRO_PREFIX = 'DVC repro' + COLLAPSED_TEXT = DVC_REPRO_PREFIX + '\n<< collapsed commits >>' + + def __init__(self, hash, parents, name, date, comment, is_target=False, target_metric=None): + self._hash = hash + self._parent_hashes = set(parents.split()) + self._name = name + self._date = date + self._comment = comment + self._is_target = is_target + self._target_metric = target_metric + + self._is_collapsed = False + + @property + def hash(self): + return self._hash + + @property + def parent_hashes(self): + return self._parent_hashes + + def add_parents(self, parent_hashes): + self._parent_hashes |= parent_hashes + + def remove_parent(self, hash): + self._parent_hashes.remove(hash) + + @property + def text(self): + metric_text = '' + if self._is_target and self._target_metric: + metric_text = '\nTarget metric: {}'.format(self._target_metric) + + if self._is_collapsed: + return self.COLLAPSED_TEXT + metric_text + + return self._comment[:self.TEXT_LIMIT] + '\n' + self.hash + metric_text + + @property + def is_repro(self): + return self._comment.startswith(self.DVC_REPRO_PREFIX) + + def make_colapsed(self): + self._is_collapsed = True + + @property + def has_target_metric(self): + return self._is_target and self._target_metric is not None + + @property + def target_metric(self): + return self._target_metric + + def set_target_metric(self, value): + self._target_metric = value + self._is_target = True \ No newline at end of file diff --git a/dvc/graph/workflow.py b/dvc/graph/workflow.py index e60c356ec..4b3db0170 100644 --- a/dvc/graph/workflow.py +++ b/dvc/graph/workflow.py @@ -8,67 +8,6 @@ class WorkflowError(DvcException): super(WorkflowError, self).__init__('Workflow error: ' + msg) -class Commit(object): - TEXT_LIMIT = 30 - DVC_REPRO_PREFIX = 'DVC repro' - COLLAPSED_TEXT = DVC_REPRO_PREFIX + '\n<< collapsed commits >>' - - def __init__(self, hash, parents, name, date, comment, is_target=False, target_metric=None): - self._hash = hash - self._parent_hashes = set(parents.split()) - self._name = name - self._date = date - self._comment = comment - self._is_target = is_target - self._target_metric = target_metric - - self._is_collapsed = False - - @property - def hash(self): - return self._hash - - @property - def parent_hashes(self): - return self._parent_hashes - - def add_parents(self, parent_hashes): - self._parent_hashes |= parent_hashes - - def remove_parent(self, hash): - self._parent_hashes.remove(hash) - - @property - def text(self): - metric_text = '' - if self._is_target and self._target_metric: - metric_text = '\nTarget metric: {}'.format(self._target_metric) - - if self._is_collapsed: - return self.COLLAPSED_TEXT + metric_text - - return self._comment[:self.TEXT_LIMIT] + '\n' + self.hash + metric_text - - @property - def is_repro(self): - return self._comment.startswith(self.DVC_REPRO_PREFIX) - - def make_colapsed(self): - self._is_collapsed = True - - @property - def has_target_metric(self): - return self._is_target and self._target_metric is not None - - @property - def target_metric(self): - return self._target_metric - - def set_target_metric(self, value): - self._target_metric = value - self._is_target = True - - class Workflow(object): def __init__(self, target, merges_map, root='', no_repro_commits=True): self._target = target diff --git a/tests/test_workflow.py b/tests/test_workflow.py index a8ec64ae3..8912a4692 100644 --- a/tests/test_workflow.py +++ b/tests/test_workflow.py @@ -1,6 +1,7 @@ from unittest import TestCase -from dvc.workflow import Workflow, Commit +from dvc.graph.workflow import Workflow +from dvc.graph.commit import Commit class TestWorkflow(TestCase):