Skip to content

Commit 1e7bc19

Browse files
Feat: Limit long lists of indirectly modified models in CLI output (#2788)
1 parent fca414e commit 1e7bc19

1 file changed

Lines changed: 36 additions & 3 deletions

File tree

sqlmesh/core/console.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class Console(abc.ABC):
6060
"""Abstract base class for defining classes used for displaying information to the user and also interact
6161
with them when their input is needed."""
6262

63+
INDIRECTLY_MODIFIED_DISPLAY_THRESHOLD = 20
64+
6365
@abc.abstractmethod
6466
def start_plan_evaluation(self, plan: Plan) -> None:
6567
"""Indicates that a new evaluation has begun."""
@@ -235,6 +237,17 @@ def show_schema_diff(self, schema_diff: SchemaDiff) -> None:
235237
def show_row_diff(self, row_diff: RowDiff, show_sample: bool = True) -> None:
236238
"""Show table summary diff."""
237239

240+
def _limit_model_names(self, tree: Tree, verbose: bool = False) -> Tree:
241+
"""Trim long indirectly modified model lists below threshold."""
242+
modified_length = len(tree.children)
243+
if not verbose and modified_length > self.INDIRECTLY_MODIFIED_DISPLAY_THRESHOLD:
244+
tree.children = [
245+
tree.children[0],
246+
Tree(f".... {modified_length-2} more ...."),
247+
tree.children[-1],
248+
]
249+
return tree
250+
238251

239252
def make_progress_bar(message: str, console: t.Optional[RichConsole] = None) -> Progress:
240253
return Progress(
@@ -728,7 +741,7 @@ def _show_summary_tree_for(
728741
if direct.children:
729742
tree.add(direct)
730743
if indirect.children:
731-
tree.add(indirect)
744+
tree.add(self._limit_model_names(indirect, self.verbose))
732745
if metadata.children:
733746
tree.add(metadata)
734747
if selected_ignored_snapshot_ids:
@@ -795,6 +808,9 @@ def _prompt_categorize(
795808
indirect_tree.add(
796809
f"[indirect]{child_snapshot.display_name(plan.environment_naming_info, default_catalog, dialect=self.dialect)}"
797810
)
811+
if indirect_tree:
812+
indirect_tree = self._limit_model_names(indirect_tree, self.verbose)
813+
798814
self._print(tree)
799815
if not no_prompts:
800816
self._get_snapshot_change_category(
@@ -822,6 +838,9 @@ def _show_categorized_snapshots(self, plan: Plan, default_catalog: t.Optional[st
822838
indirect_tree.add(
823839
f"[indirect]{child_snapshot.display_name(plan.environment_naming_info, default_catalog, dialect=self.dialect)} ({child_category_str})"
824840
)
841+
if indirect_tree:
842+
indirect_tree = self._limit_model_names(indirect_tree, self.verbose)
843+
825844
self._print(Syntax(context_diff.text_diff(snapshot.name), "sql", word_wrap=True))
826845
self._print(tree)
827846

@@ -1550,10 +1569,22 @@ def show_model_difference_summary(
15501569
self._print(f"```diff\n{context_diff.text_diff(snapshot.name)}\n```")
15511570
if indirectly_modified:
15521571
self._print("\n**Indirectly Modified:**")
1553-
for snapshot in sorted(indirectly_modified):
1572+
indirectly_modified = sorted(indirectly_modified)
1573+
modified_length = len(indirectly_modified)
1574+
if (
1575+
not self.verbose
1576+
and modified_length > self.INDIRECTLY_MODIFIED_DISPLAY_THRESHOLD
1577+
):
15541578
self._print(
1555-
f"- `{snapshot.display_name(environment_naming_info, default_catalog, dialect=self.dialect)}`"
1579+
f"- `{indirectly_modified[0].display_name(environment_naming_info, default_catalog, dialect=self.dialect)}`\n"
1580+
f"- `.... {modified_length-2} more ....`\n"
1581+
f"- `{indirectly_modified[-1].display_name(environment_naming_info, default_catalog, dialect=self.dialect)}`"
15561582
)
1583+
else:
1584+
for snapshot in indirectly_modified:
1585+
self._print(
1586+
f"- `{snapshot.display_name(environment_naming_info, default_catalog, dialect=self.dialect)}`"
1587+
)
15571588
if metadata_modified:
15581589
self._print("\n**Metadata Updated:**")
15591590
for snapshot in sorted(metadata_modified):
@@ -1607,6 +1638,8 @@ def _show_categorized_snapshots(self, plan: Plan, default_catalog: t.Optional[st
16071638
indirect_tree.add(
16081639
f"[indirect]{child_snapshot.display_name(plan.environment_naming_info, default_catalog, dialect=self.dialect)} ({child_category_str})"
16091640
)
1641+
if indirect_tree:
1642+
indirect_tree = self._limit_model_names(indirect_tree, self.verbose)
16101643
self._print(f"```diff\n{context_diff.text_diff(snapshot.name)}\n```\n")
16111644
self._print("```\n")
16121645
self._print(tree)

0 commit comments

Comments
 (0)