Skip to content

Commit 23f49ba

Browse files
committed
Fix extraneous spacing between annotation and run time
1 parent 666419d commit 23f49ba

2 files changed

Lines changed: 50 additions & 48 deletions

File tree

sqlmesh/core/console.py

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ def update_snapshot_evaluation_progress(
891891
self.evaluation_column_widths["duration"]
892892
)
893893

894-
msg = f"{batch} {display_name} {annotation} {duration}".replace(
894+
msg = f"{batch} {display_name} {annotation} {duration}".replace(
895895
CHECK_MARK, GREEN_CHECK_MARK
896896
)
897897

@@ -3359,54 +3359,56 @@ def _create_evaluation_model_annotation(snapshot: Snapshot, interval_info: t.Opt
33593359
return interval_info if interval_info else ""
33603360

33613361

3362-
def _calculate_interval_str_len(batched_intervals: t.Dict[Snapshot, t.List[Interval]]) -> int:
3362+
def _calculate_interval_str_len(snapshot: Snapshot, intervals: t.List[Interval]) -> int:
33633363
interval_str_len = 0
3364-
for snapshot, intervals in batched_intervals.items():
3365-
for interval in intervals:
3366-
interval_str_len = max(
3367-
interval_str_len,
3368-
len(
3369-
_create_evaluation_model_annotation(
3370-
snapshot, _format_evaluation_model_interval(snapshot, interval)
3371-
)
3372-
),
3373-
)
3364+
for interval in intervals:
3365+
interval_str_len = max(
3366+
interval_str_len,
3367+
len(
3368+
_create_evaluation_model_annotation(
3369+
snapshot, _format_evaluation_model_interval(snapshot, interval)
3370+
)
3371+
),
3372+
)
33743373
return interval_str_len
33753374

33763375

3377-
def _calculate_audit_str_len(batched_intervals: t.Dict[Snapshot, t.List[Interval]]) -> int:
3376+
def _calculate_audit_str_len(snapshot: Snapshot) -> int:
33783377
# The annotation includes audit results. We cannot build the audits result string
33793378
# until after evaluation occurs, but we must determine the annotation column width here.
33803379
# Therefore, we add enough padding for the longest possible audits result string.
33813380
audit_str_len = 0
33823381
audit_base_str_len = len(f", audits ") + 1 # +1 for check/X
3383-
for snapshot in batched_intervals:
3384-
if snapshot.is_audit:
3382+
if snapshot.is_audit:
3383+
# +1 for "1" audit count, +1 for red X
3384+
audit_str_len = max(
3385+
audit_str_len, audit_base_str_len + (2 if not snapshot.audit.blocking else 1)
3386+
)
3387+
if snapshot.is_model and snapshot.model.audits:
3388+
num_audits = len(snapshot.model.audits_with_args)
3389+
num_nonblocking_audits = sum(
3390+
1
3391+
for audit in snapshot.model.audits_with_args
3392+
if not audit[0].blocking
3393+
or ("blocking" in audit[1] and audit[1]["blocking"] == exp.false())
3394+
)
3395+
if num_audits == 1:
33853396
# +1 for "1" audit count, +1 for red X
3386-
audit_str_len = max(
3387-
audit_str_len, audit_base_str_len + (2 if not snapshot.audit.blocking else 1)
3388-
)
3389-
if snapshot.is_model and snapshot.model.audits:
3390-
num_audits = len(snapshot.model.audits_with_args)
3391-
num_nonblocking_audits = sum(
3392-
1
3393-
for audit in snapshot.model.audits_with_args
3394-
if not audit[0].blocking
3395-
or ("blocking" in audit[1] and audit[1]["blocking"] == exp.false())
3396-
)
3397-
if num_audits == 1:
3398-
# +1 for "1" audit count, +1 for red X
3399-
audit_len = audit_base_str_len + (2 if num_nonblocking_audits else 1)
3400-
else:
3401-
audit_len = audit_base_str_len + len(str(num_audits))
3402-
if num_nonblocking_audits:
3403-
# +1 for space, +1 for red X
3404-
audit_len += len(str(num_nonblocking_audits)) + 2
3405-
audit_str_len = max(audit_str_len, audit_len)
3397+
audit_len = audit_base_str_len + (2 if num_nonblocking_audits else 1)
3398+
else:
3399+
audit_len = audit_base_str_len + len(str(num_audits))
3400+
if num_nonblocking_audits:
3401+
# +1 for space, +1 for red X
3402+
audit_len += len(str(num_nonblocking_audits)) + 2
3403+
audit_str_len = max(audit_str_len, audit_len)
34063404
return audit_str_len
34073405

34083406

34093407
def _calculate_annotation_str_len(batched_intervals: t.Dict[Snapshot, t.List[Interval]]) -> int:
3410-
return _calculate_interval_str_len(batched_intervals) + _calculate_audit_str_len(
3411-
batched_intervals
3412-
)
3408+
annotation_str_len = 0
3409+
for snapshot, intervals in batched_intervals.items():
3410+
annotation_str_len = max(
3411+
annotation_str_len,
3412+
_calculate_interval_str_len(snapshot, intervals) + _calculate_audit_str_len(snapshot),
3413+
)
3414+
return annotation_str_len

tests/cli/test_cli.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def test_plan(runner, tmp_path):
182182
assert_plan_success(result)
183183
# 'Models needing backfill' section and eval progress bar should display the same inclusive intervals
184184
assert "sqlmesh_example.incremental_model: [2020-01-01 - 2022-12-31]" in result.output
185-
assert "sqlmesh_example.incremental_model [insert 2020-01-01 - 2022-12-31]" in result.output
185+
assert "sqlmesh_example.incremental_model [insert 2020-01-01 - 2022-12-31]" in result.output
186186

187187

188188
def test_plan_skip_tests(runner, tmp_path):
@@ -243,7 +243,7 @@ def test_plan_restate_model(runner, tmp_path):
243243
assert result.exit_code == 0
244244
assert_duckdb_test(result)
245245
assert "No changes to plan: project files match the `prod` environment" in result.output
246-
assert "sqlmesh_example.full_model [full refresh" in result.output
246+
assert "sqlmesh_example.full_model [full refresh" in result.output
247247
assert_model_batches_executed(result)
248248
assert_virtual_layer_updated(result)
249249

@@ -568,8 +568,8 @@ def test_plan_nonbreaking(runner, tmp_path):
568568
assert "+ 'a' AS new_col" in result.output
569569
assert "Directly Modified: sqlmesh_example.incremental_model (Non-breaking)" in result.output
570570
assert "sqlmesh_example.full_model (Indirect Non-breaking)" in result.output
571-
assert "sqlmesh_example.incremental_model [insert" in result.output
572-
assert "sqlmesh_example.full_model [full refresh" not in result.output
571+
assert "sqlmesh_example.incremental_model [insert" in result.output
572+
assert "sqlmesh_example.full_model [full refresh" not in result.output
573573
assert_backfill_success(result)
574574

575575

@@ -626,8 +626,8 @@ def test_plan_breaking(runner, tmp_path):
626626
assert result.exit_code == 0
627627
assert "+ item_id + 1 AS item_id," in result.output
628628
assert "Directly Modified: sqlmesh_example.full_model (Breaking)" in result.output
629-
assert "sqlmesh_example.full_model [full refresh" in result.output
630-
assert "sqlmesh_example.incremental_model [insert" not in result.output
629+
assert "sqlmesh_example.full_model [full refresh" in result.output
630+
assert "sqlmesh_example.incremental_model [insert" not in result.output
631631
assert_backfill_success(result)
632632

633633

@@ -665,8 +665,8 @@ def test_plan_dev_select(runner, tmp_path):
665665
assert "+ item_id + 1 AS item_id," not in result.output
666666
assert "Directly Modified: sqlmesh_example__dev.full_model (Breaking)" not in result.output
667667
# only incremental_model backfilled
668-
assert "sqlmesh_example__dev.incremental_model [insert" in result.output
669-
assert "sqlmesh_example__dev.full_model [full refresh" not in result.output
668+
assert "sqlmesh_example__dev.incremental_model [insert" in result.output
669+
assert "sqlmesh_example__dev.full_model [full refresh" not in result.output
670670
assert_backfill_success(result)
671671

672672

@@ -704,8 +704,8 @@ def test_plan_dev_backfill(runner, tmp_path):
704704
"Directly Modified: sqlmesh_example__dev.incremental_model (Non-breaking)" in result.output
705705
)
706706
# only incremental_model backfilled
707-
assert "sqlmesh_example__dev.incremental_model [insert" in result.output
708-
assert "sqlmesh_example__dev.full_model [full refresh" not in result.output
707+
assert "sqlmesh_example__dev.incremental_model [insert" in result.output
708+
assert "sqlmesh_example__dev.full_model [full refresh" not in result.output
709709
assert_backfill_success(result)
710710

711711

0 commit comments

Comments
 (0)