diff --git a/dvc/cli.py b/dvc/cli.py index a86ee86f8..106e840ec 100644 --- a/dvc/cli.py +++ b/dvc/cli.py @@ -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): diff --git a/dvc/command/show_workflow.py b/dvc/command/show_workflow.py index 83ed1d163..8008939a4 100644 --- a/dvc/command/show_workflow.py +++ b/dvc/command/show_workflow.py @@ -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 diff --git a/dvc/graph/commit.py b/dvc/graph/commit.py index 79b6e4c66..7ccac14aa 100644 --- a/dvc/graph/commit.py +++ b/dvc/graph/commit.py @@ -1,7 +1,7 @@ class Commit(object): TEXT_LIMIT = 30 DVC_REPRO_PREFIX = 'DVC repro' - COLLAPSED_TEXT = DVC_REPRO_PREFIX + ' <>' + COLLAPSED_TEXT = DVC_REPRO_PREFIX + ' <>' 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 + diff --git a/dvc/graph/workflow.py b/dvc/graph/workflow.py index f33410b17..1e6e1db87 100644 --- a/dvc/graph/workflow.py +++ b/dvc/graph/workflow.py @@ -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