Skip to content

Commit 151da8c

Browse files
authored
Feat: improve CLI virtual layer progress bar (#4064)
1 parent 3f102a0 commit 151da8c

2 files changed

Lines changed: 36 additions & 7 deletions

File tree

sqlmesh/core/console.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,7 @@ def __init__(
676676
self.evaluation_total_task: t.Optional[TaskID] = None
677677
self.evaluation_model_progress: t.Optional[Progress] = None
678678
self.evaluation_model_tasks: t.Dict[str, TaskID] = {}
679+
self.evaluation_model_batch_sizes: t.Dict[Snapshot, int] = {}
679680
self.evaluation_column_widths: t.Dict[str, int] = {}
680681

681682
# Put in temporary values that are replaced when evaluating
@@ -967,10 +968,13 @@ def start_promotion_progress(
967968
"Updating virtual layer ", self.console, justify="left"
968969
)
969970

971+
snapshots_with_virtual_views = [
972+
s for s in snapshots if s.is_model and not s.is_symbolic
973+
]
970974
self.promotion_progress.start()
971975
self.promotion_task = self.promotion_progress.add_task(
972976
f"Virtually updating {environment_naming_info.name}...",
973-
total=len(snapshots),
977+
total=len(snapshots_with_virtual_views),
974978
)
975979

976980
# determine name column widths if we're printing names
@@ -983,24 +987,34 @@ def start_promotion_progress(
983987
dialect=self.dialect,
984988
)
985989
)
986-
for snapshot in snapshots
990+
for snapshot in snapshots_with_virtual_views
987991
)
988992

989993
self.environment_naming_info = environment_naming_info
990994
self.default_catalog = default_catalog
991995

992996
def update_promotion_progress(self, snapshot: SnapshotInfoLike, promoted: bool) -> None:
993997
"""Update the snapshot promotion progress."""
994-
if self.promotion_progress is not None and self.promotion_task is not None:
998+
if (
999+
self.promotion_progress is not None
1000+
and self.promotion_task is not None
1001+
and snapshot.is_model
1002+
and not snapshot.is_symbolic
1003+
):
9951004
if self.verbosity >= Verbosity.VERBOSE:
9961005
display_name = snapshot.display_name(
9971006
self.environment_naming_info,
9981007
self.default_catalog if self.verbosity < Verbosity.VERY_VERBOSE else None,
9991008
dialect=self.dialect,
10001009
).ljust(self.promotion_column_widths["name"])
1001-
action_str = (
1002-
"[green]promoted[/green]" if promoted else "[yellow]demoted[/yellow]"
1003-
).ljust(len("promoted"))
1010+
action_str = ""
1011+
if promoted:
1012+
action_str = (
1013+
"[yellow]updated[/yellow]"
1014+
if snapshot.previous_version
1015+
else "[green]created[/green]"
1016+
)
1017+
action_str = action_str or "[red]dropped[/red]"
10041018
self.promotion_progress.live.console.print(f"{display_name} {action_str}")
10051019
self.promotion_progress.update(self.promotion_task, refresh=True, advance=1)
10061020

tests/cli/test_cli.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,22 @@ def test_plan_verbose(runner, tmp_path):
295295
)
296296
assert_plan_success(result)
297297
assert "sqlmesh_example.seed_model created" in result.output
298-
assert "sqlmesh_example.seed_model promoted" in result.output
298+
assert "sqlmesh_example.full_model created" in result.output
299+
300+
# confirm virtual layer action labels correct
301+
update_incremental_model(tmp_path)
302+
import os
303+
304+
os.remove(tmp_path / "models" / "full_model.sql")
305+
306+
# Input: `y` to apply and backfill
307+
result = runner.invoke(
308+
cli, ["--log-file-dir", tmp_path, "--paths", tmp_path, "plan", "--verbose"], input="y\n"
309+
)
310+
assert result.exit_code == 0
311+
assert_backfill_success(result)
312+
assert "sqlmesh_example.incremental_model updated" in result.output
313+
assert "sqlmesh_example.full_model dropped" in result.output
299314

300315

301316
def test_plan_very_verbose(runner, tmp_path, copy_to_temp_path):

0 commit comments

Comments
 (0)