mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-07 23:09:21 +01:00
Refactoring: extract Commits to a separate file
This commit is contained in:
+2
-1
@@ -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):
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user