mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-04 23:09:44 +01:00
Add cmd options
This commit is contained in:
+13
@@ -422,6 +422,19 @@ def parse_args(argv=None):
|
||||
'target',
|
||||
nargs='?',
|
||||
help='Target metric data file')
|
||||
workflow_parser.add_argument(
|
||||
'-a',
|
||||
'--all-commits',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help='Show all commits')
|
||||
workflow_parser.add_argument(
|
||||
'-d',
|
||||
'--deltas',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help='Show only metric deltas')
|
||||
|
||||
workflow_parser.set_defaults(func=CmdShowWorkflow)
|
||||
|
||||
if isinstance(argv, str):
|
||||
|
||||
@@ -21,7 +21,7 @@ class CmdShowWorkflow(CmdBase):
|
||||
Logger.debug(u'Set show workflow target as {}'.format(target))
|
||||
|
||||
wf = self.git.get_all_commits(target, self.settings)
|
||||
wf.build_graph()
|
||||
wf.build_graph(self.settings.parsed_args.all_commits, self.settings.parsed_args.deltas)
|
||||
return 0
|
||||
|
||||
@property
|
||||
|
||||
+15
-10
@@ -1,7 +1,7 @@
|
||||
class Commit(object):
|
||||
TEXT_LIMIT = 30
|
||||
DVC_REPRO_PREFIX = 'DVC repro'
|
||||
COLLAPSED_TEXT = DVC_REPRO_PREFIX + ' <<collapsed commits>>'
|
||||
COLLAPSED_TEXT = DVC_REPRO_PREFIX + ' <<collapsed>>'
|
||||
|
||||
def __init__(self, hash, parents, name, date, comment,
|
||||
is_target=False,
|
||||
@@ -39,32 +39,36 @@ class Commit(object):
|
||||
if self._branch_tips:
|
||||
branch_text = 'Branch tips: {}\n'.format(', '.join(self._branch_tips))
|
||||
|
||||
if self._is_collapsed:
|
||||
return branch_text + self.COLLAPSED_TEXT + self._text_metrics_line()
|
||||
|
||||
return branch_text + self._text_comment() + self._text_metrics_line() + '\n' + self._text_hash()
|
||||
return self._text_metrics_line() + branch_text + self._text_comment
|
||||
|
||||
def _text_hash(self):
|
||||
return 'Commit: ' + self.hash
|
||||
|
||||
@property
|
||||
def _text_comment(self):
|
||||
if len(self._comment) < self.TEXT_LIMIT:
|
||||
return self._comment
|
||||
return self._comment[:self.TEXT_LIMIT] + '...'
|
||||
result = self.hash + ': '
|
||||
if self._is_collapsed:
|
||||
result += self.COLLAPSED_TEXT
|
||||
elif len(self._comment) < self.TEXT_LIMIT:
|
||||
result += self._comment
|
||||
else:
|
||||
result += self._comment[:self.TEXT_LIMIT] + '...'
|
||||
return result
|
||||
|
||||
def _text_metrics_line(self):
|
||||
result = ''
|
||||
if self._is_target and self._target_metric:
|
||||
result = '\nTarget: {}'.format(self._target_metric)
|
||||
result = 'Target: {}'.format(self._target_metric)
|
||||
if self._target_metric_delta is not None:
|
||||
result += ' ({:+f})'.format(self._target_metric_delta)
|
||||
result += '\n'
|
||||
return result
|
||||
|
||||
@property
|
||||
def is_repro(self):
|
||||
return self._comment.startswith(self.DVC_REPRO_PREFIX)
|
||||
|
||||
def make_colapsed(self):
|
||||
def make_collapsed(self):
|
||||
self._is_collapsed = True
|
||||
|
||||
@property
|
||||
@@ -93,3 +97,4 @@ class Commit(object):
|
||||
@property
|
||||
def target_metric_delta(self):
|
||||
return self._target_metric_delta
|
||||
|
||||
|
||||
+11
-6
@@ -10,7 +10,7 @@ class WorkflowError(DvcException):
|
||||
|
||||
|
||||
class Workflow(object):
|
||||
def __init__(self, target, merges_map, branches_map=None, no_repro_commits=True):
|
||||
def __init__(self, target, merges_map, branches_map=None):
|
||||
self._target = target
|
||||
self._merges_map = merges_map
|
||||
self._branches_map = branches_map
|
||||
@@ -20,8 +20,6 @@ class Workflow(object):
|
||||
|
||||
self._edges = {}
|
||||
self._back_edges = {}
|
||||
|
||||
self._no_repro_commits = no_repro_commits
|
||||
pass
|
||||
|
||||
def add_commit(self, commit):
|
||||
@@ -39,13 +37,16 @@ class Workflow(object):
|
||||
self._root_hash = commit.hash
|
||||
pass
|
||||
|
||||
def build_graph(self):
|
||||
def build_graph(self, all_commits, deltas):
|
||||
g = nx.DiGraph(name='DVC Workflow', directed=False)
|
||||
|
||||
self.derive_target_metric_deltas()
|
||||
|
||||
if self._no_repro_commits:
|
||||
if not all_commits:
|
||||
self.collapse_repro_commits()
|
||||
elif deltas:
|
||||
self.collapse_repro_commits()
|
||||
self.deltas_only()
|
||||
|
||||
for hash in set(self._edges.keys() + self._back_edges.keys()):
|
||||
commit = self._commits[hash]
|
||||
@@ -87,6 +88,10 @@ class Workflow(object):
|
||||
|
||||
self._build_graph(next, g)
|
||||
|
||||
def deltas_only(self):
|
||||
|
||||
pass
|
||||
|
||||
def collapse_repro_commits(self):
|
||||
hashes_to_remove = []
|
||||
for commit in self._commits.values():
|
||||
@@ -116,7 +121,7 @@ class Workflow(object):
|
||||
|
||||
return True
|
||||
else:
|
||||
commit.make_colapsed()
|
||||
commit.make_collapsed()
|
||||
return False
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user