Skip to content

Commit 8f0d61d

Browse files
committed
fix: cache Tree object in StepTracker to prevent duplicate banner
The StepTracker.render() method was creating a new Tree object each time it was called, causing duplicate 'Initialize Specify Project' titles when Live.update() was invoked multiple times. Now the Tree is cached in self._tree and reused: - First render: creates new Tree and caches it - Subsequent renders: clears children and re-adds them to the same Tree This ensures only one Tree object exists with a single title.
1 parent 3942f6e commit 8f0d61d

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

src/specify_cli/__init__.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ def __init__(self, title: str):
296296
"skipped": 4,
297297
}
298298
self._refresh_cb = None # callable to trigger UI refresh
299+
self._tree = None # cached Tree object
299300

300301
def attach_refresh(self, cb):
301302
self._refresh_cb = cb
@@ -341,7 +342,13 @@ def _maybe_refresh(self):
341342
pass
342343

343344
def render(self):
344-
tree = Tree(f"{accent(self.title)}", guide_style="grey50")
345+
# Reuse cached Tree to avoid duplicate banner issue
346+
if self._tree is None:
347+
self._tree = Tree(f"{accent(self.title)}", guide_style="grey50")
348+
else:
349+
# Clear existing children and re-add them
350+
self._tree.children = []
351+
345352
for step in self.steps:
346353
label = step["label"]
347354
detail_text = step["detail"].strip() if step["detail"] else ""
@@ -375,8 +382,8 @@ def render(self):
375382
else:
376383
line = f"{symbol} [white]{label}[/white]"
377384

378-
tree.add(line)
379-
return tree
385+
self._tree.add(line)
386+
return self._tree
380387

381388

382389
def get_key():
@@ -1578,10 +1585,10 @@ def init(
15781585
]:
15791586
tracker.add(key, label)
15801587

1581-
with Live("", console=console, refresh_per_second=8, transient=True) as live:
1582-
initial_render = tracker.render()
1588+
with Live(
1589+
tracker.render(), console=console, refresh_per_second=8, transient=True
1590+
) as live:
15831591
tracker.attach_refresh(lambda: live.update(tracker.render()))
1584-
live.update(initial_render)
15851592
try:
15861593
# Integration-based scaffolding
15871594
from .integrations.manifest import IntegrationManifest

0 commit comments

Comments
 (0)