Skip to content

Commit 466f249

Browse files
authored
refactor: further break apart console interface (#4167)
1 parent 4858861 commit 466f249

File tree

1 file changed

+61
-37
lines changed

1 file changed

+61
-37
lines changed

sqlmesh/core/console.py

Lines changed: 61 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@
8484

8585

8686
class LinterConsole(abc.ABC):
87+
"""Console for displaying linter violations"""
88+
8789
@abc.abstractmethod
8890
def show_linter_violations(
8991
self, violations: t.List[RuleViolation], model: Model, is_error: bool = False
@@ -92,6 +94,8 @@ def show_linter_violations(
9294

9395

9496
class StateExporterConsole(abc.ABC):
97+
"""Console for describing a state export"""
98+
9599
@abc.abstractmethod
96100
def start_state_export(
97101
self,
@@ -122,6 +126,8 @@ def stop_state_export(self, success: bool, output_file: Path) -> None:
122126

123127

124128
class StateImporterConsole(abc.ABC):
129+
"""Console for describing a state import"""
130+
125131
@abc.abstractmethod
126132
def start_state_import(
127133
self,
@@ -152,6 +158,8 @@ def stop_state_import(self, success: bool, input_file: Path) -> None:
152158

153159

154160
class JanitorConsole(abc.ABC):
161+
"""Console for describing a janitor / snapshot cleanup run"""
162+
155163
@abc.abstractmethod
156164
def start_cleanup(self, ignore_ttl: bool) -> bool:
157165
"""Start a janitor / snapshot cleanup run.
@@ -176,7 +184,45 @@ def stop_cleanup(self, success: bool = True) -> None:
176184
"""
177185

178186

179-
class Console(LinterConsole, StateExporterConsole, StateImporterConsole, JanitorConsole, abc.ABC):
187+
class EnvironmentsConsole(abc.ABC):
188+
"""Console for displaying environments"""
189+
190+
@abc.abstractmethod
191+
def print_environments(self, environments_summary: t.Dict[str, int]) -> None:
192+
"""Prints all environment names along with expiry datetime."""
193+
194+
195+
class DifferenceConsole(abc.ABC):
196+
"""Console for displaying environment differences"""
197+
198+
@abc.abstractmethod
199+
def show_environment_difference_summary(
200+
self,
201+
context_diff: ContextDiff,
202+
no_diff: bool = True,
203+
) -> None:
204+
"""Displays a summary of differences for the environment."""
205+
206+
@abc.abstractmethod
207+
def show_model_difference_summary(
208+
self,
209+
context_diff: ContextDiff,
210+
environment_naming_info: EnvironmentNamingInfo,
211+
default_catalog: t.Optional[str],
212+
no_diff: bool = True,
213+
) -> None:
214+
"""Displays a summary of differences for the given models."""
215+
216+
217+
class Console(
218+
LinterConsole,
219+
StateExporterConsole,
220+
StateImporterConsole,
221+
JanitorConsole,
222+
EnvironmentsConsole,
223+
DifferenceConsole,
224+
abc.ABC,
225+
):
180226
"""Abstract base class for defining classes used for displaying information to the user and also interact
181227
with them when their input is needed."""
182228

@@ -281,24 +327,6 @@ def update_env_migration_progress(self, num_tasks: int) -> None:
281327
def stop_env_migration_progress(self, success: bool = True) -> None:
282328
"""Stop the environment migration progress."""
283329

284-
@abc.abstractmethod
285-
def show_environment_difference_summary(
286-
self,
287-
context_diff: ContextDiff,
288-
no_diff: bool = True,
289-
) -> None:
290-
"""Displays a summary of differences for the environment."""
291-
292-
@abc.abstractmethod
293-
def show_model_difference_summary(
294-
self,
295-
context_diff: ContextDiff,
296-
environment_naming_info: EnvironmentNamingInfo,
297-
default_catalog: t.Optional[str],
298-
no_diff: bool = True,
299-
) -> None:
300-
"""Displays a summary of differences for the given models."""
301-
302330
@abc.abstractmethod
303331
def plan(
304332
self,
@@ -400,24 +428,6 @@ def show_row_diff(
400428
) -> None:
401429
"""Show table summary diff."""
402430

403-
@abc.abstractmethod
404-
def print_environments(self, environments_summary: t.Dict[str, int]) -> None:
405-
"""Prints all environment names along with expiry datetime."""
406-
407-
def _limit_model_names(self, tree: Tree, verbosity: Verbosity = Verbosity.DEFAULT) -> Tree:
408-
"""Trim long indirectly modified model lists below threshold."""
409-
modified_length = len(tree.children)
410-
if (
411-
verbosity < Verbosity.VERY_VERBOSE
412-
and modified_length > self.INDIRECTLY_MODIFIED_DISPLAY_THRESHOLD
413-
):
414-
tree.children = [
415-
tree.children[0],
416-
Tree(f".... {modified_length - 2} more ...."),
417-
tree.children[-1],
418-
]
419-
return tree
420-
421431

422432
class NoopConsole(Console):
423433
def start_plan_evaluation(self, plan: EvaluatablePlan) -> None:
@@ -727,6 +737,20 @@ def __init__(
727737
self.dialect = dialect
728738
self.ignore_warnings = ignore_warnings
729739

740+
def _limit_model_names(self, tree: Tree, verbosity: Verbosity = Verbosity.DEFAULT) -> Tree:
741+
"""Trim long indirectly modified model lists below threshold."""
742+
modified_length = len(tree.children)
743+
if (
744+
verbosity < Verbosity.VERY_VERBOSE
745+
and modified_length > self.INDIRECTLY_MODIFIED_DISPLAY_THRESHOLD
746+
):
747+
tree.children = [
748+
tree.children[0],
749+
Tree(f".... {modified_length - 2} more ...."),
750+
tree.children[-1],
751+
]
752+
return tree
753+
730754
def _print(self, value: t.Any, **kwargs: t.Any) -> None:
731755
self.console.print(value, **kwargs)
732756

0 commit comments

Comments
 (0)