From 102817e53ad87f5516857cb615e2ec70614f87b6 Mon Sep 17 00:00:00 2001 From: Saugat Pachhai Date: Fri, 30 Apr 2021 15:11:57 +0545 Subject: [PATCH] simplify experiments row collection logic (#5901) --- dvc/command/experiments.py | 70 +++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/dvc/command/experiments.py b/dvc/command/experiments.py index 9584de477..344fc658c 100644 --- a/dvc/command/experiments.py +++ b/dvc/command/experiments.py @@ -139,43 +139,43 @@ def _collect_rows( new_checkpoint = True for i, (rev, exp) in enumerate(experiments.items()): queued = str(exp.get("queued") or "") - tip = exp.get("checkpoint_tip") - parent = "" - tree = "" - if rev == "baseline": - if Git.is_sha(base_rev): - name_rev = base_rev[:7] - else: - name_rev = base_rev - name = exp.get("name", name_rev) + is_baseline = rev == "baseline" + + if is_baseline: + name_rev = base_rev[:7] if Git.is_sha(base_rev) else base_rev else: - if tip: - parent_rev = exp.get("checkpoint_parent", "") - parent_exp = experiments.get(parent_rev, {}) - parent_tip = parent_exp.get("checkpoint_tip") - if tip == parent_tip: - if new_checkpoint: - tree = "│ ╓" - else: - tree = "│ ╟" - new_checkpoint = False - else: - if parent_rev == base_rev: - tree = "├─╨" - else: - tree = "│ ╟" - parent = parent_rev[:7] - new_checkpoint = True + name_rev = rev[:7] + + exp_name = exp.get("name", "") + if is_baseline: + name = exp_name or name_rev + elif exp_name: + name = f"{rev[:7]} [[bold]{exp['name']}[/]]" + else: + name = name_rev + + tip = exp.get("checkpoint_tip") + + parent_rev = exp.get("checkpoint_parent", "") + parent_exp = experiments.get(parent_rev, {}) + parent_tip = parent_exp.get("checkpoint_tip") + + parent = "" + if is_baseline: + tree = "" + elif tip: + if tip == parent_tip: + tree = "│ ╓" if new_checkpoint else "│ ╟" + elif parent_rev == base_rev: + tree = "├─╨" else: - if i < len(experiments) - 1: - tree = "├──" - else: - tree = "└──" - new_checkpoint = True - if "name" in exp: - name = f"{rev[:7]} [[bold]{exp['name']}[/]]" - else: - name = rev[:7] + tree = "│ ╟" + parent = parent_rev[:7] + else: + tree = "├──" if i < len(experiments) - 1 else "└──" + + if not is_baseline: + new_checkpoint = not (tip and tip == parent_tip) row = [ name,