Skip to content

Commit 8ef7700

Browse files
committed
Use -v count instead of second argument
1 parent 4c3c157 commit 8ef7700

10 files changed

Lines changed: 54 additions & 72 deletions

File tree

sqlmesh/cli/main.py

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from sqlmesh.cli.example_project import ProjectTemplate, init_example_project
1414
from sqlmesh.core.analytics import cli_analytics
1515
from sqlmesh.core.console import configure_console, get_console
16-
from sqlmesh.core.constants import Verbosity
16+
from sqlmesh.utils import Verbosity
1717
from sqlmesh.core.config import load_configs
1818
from sqlmesh.core.context import Context
1919
from sqlmesh.utils.date import TimeLike
@@ -439,14 +439,12 @@ def diff(ctx: click.Context, environment: t.Optional[str] = None) -> None:
439439
help="Output text differences for the rendered versions of the models and standalone audits",
440440
)
441441
@opt.verbose
442-
@opt.very_verbose
443442
@click.pass_context
444443
@error_handler
445444
@cli_analytics
446445
def plan(
447446
ctx: click.Context,
448-
verbose: bool,
449-
very_verbose: bool,
447+
verbose: int,
450448
environment: t.Optional[str] = None,
451449
**kwargs: t.Any,
452450
) -> None:
@@ -456,10 +454,8 @@ def plan(
456454
select_models = kwargs.pop("select_model") or None
457455
allow_destructive_models = kwargs.pop("allow_destructive_model") or None
458456
backfill_models = kwargs.pop("backfill_model") or None
457+
setattr(get_console(), "verbosity", Verbosity(verbose))
459458

460-
verbosity = Verbosity.VERBOSE if verbose else Verbosity.DEFAULT
461-
verbosity = Verbosity.VERY_VERBOSE if very_verbose else verbosity
462-
setattr(get_console(), "verbosity", verbosity)
463459
context.plan(
464460
environment,
465461
restate_models=restate_models,
@@ -639,7 +635,6 @@ def create_test(
639635
@cli.command("test")
640636
@opt.match_pattern
641637
@opt.verbose
642-
@opt.very_verbose
643638
@click.option(
644639
"--preserve-fixtures",
645640
is_flag=True,
@@ -653,19 +648,15 @@ def create_test(
653648
def test(
654649
obj: Context,
655650
k: t.List[str],
656-
verbose: bool,
657-
very_verbose: bool,
651+
verbose: int,
658652
preserve_fixtures: bool,
659653
tests: t.List[str],
660654
) -> None:
661655
"""Run model unit tests."""
662-
verbosity = Verbosity.VERBOSE if verbose else Verbosity.DEFAULT
663-
verbosity = Verbosity.VERY_VERBOSE if very_verbose else verbosity
664-
665656
result = obj.test(
666657
match_patterns=k,
667658
tests=tests,
668-
verbosity=verbosity,
659+
verbosity=Verbosity(verbose),
669660
preserve_fixtures=preserve_fixtures,
670661
)
671662
if not result.wasSuccessful():
@@ -714,20 +705,16 @@ def fetchdf(ctx: click.Context, sql: str) -> None:
714705
help="Skip the connection test.",
715706
)
716707
@opt.verbose
717-
@opt.very_verbose
718708
@click.pass_obj
719709
@error_handler
720710
@cli_analytics
721-
def info(obj: Context, skip_connection: bool, verbose: bool, very_verbose: bool) -> None:
711+
def info(obj: Context, skip_connection: bool, verbose: int) -> None:
722712
"""
723713
Print information about a SQLMesh project.
724714
725715
Includes counts of project models and macros and connection tests for the data warehouse.
726716
"""
727-
verbosity = Verbosity.VERBOSE if verbose else Verbosity.DEFAULT
728-
verbosity = Verbosity.VERY_VERBOSE if very_verbose else verbosity
729-
730-
obj.print_info(skip_connection=skip_connection, verbosity=verbosity)
717+
obj.print_info(skip_connection=skip_connection, verbosity=Verbosity(verbose))
731718

732719

733720
@cli.command("ui")
@@ -918,7 +905,6 @@ def rewrite(obj: Context, sql: str, read: str = "", write: str = "") -> None:
918905
default=0.7,
919906
)
920907
@opt.verbose
921-
@opt.very_verbose
922908
@click.pass_context
923909
@error_handler
924910
@cli_analytics
@@ -927,22 +913,18 @@ def prompt(
927913
prompt: str,
928914
evaluate: bool,
929915
temperature: float,
930-
verbose: bool,
931-
very_verbose: bool,
916+
verbose: int,
932917
) -> None:
933918
"""Uses LLM to generate a SQL query from a prompt."""
934919
from sqlmesh.integrations.llm import LLMIntegration
935920

936-
verbosity = Verbosity.VERBOSE if verbose else Verbosity.DEFAULT
937-
verbosity = Verbosity.VERY_VERBOSE if very_verbose else verbosity
938-
939921
context = ctx.obj
940922

941923
llm_integration = LLMIntegration(
942924
context.models.values(),
943925
context.engine_adapter.dialect,
944926
temperature=temperature,
945-
verbosity=verbosity,
927+
verbosity=Verbosity(verbose),
946928
)
947929
query = llm_integration.query(prompt)
948930

sqlmesh/cli/options.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,6 @@
5151
verbose = click.option(
5252
"-v",
5353
"--verbose",
54-
is_flag=True,
55-
help="Verbose output.",
56-
)
57-
58-
very_verbose = click.option(
59-
"-vv",
60-
"--very-verbose",
61-
is_flag=True,
62-
help="Very verbose output.",
54+
count=True,
55+
help="Verbose output. Use -vv for very verbose output.",
6356
)

sqlmesh/core/console.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from rich.syntax import Syntax
2525
from rich.table import Table
2626
from rich.tree import Tree
27-
from sqlmesh.core.constants import Verbosity
27+
2828
from sqlmesh.core.environment import EnvironmentNamingInfo
2929
from sqlmesh.core.linter.rule import RuleViolation
3030
from sqlmesh.core.model import Model
@@ -36,6 +36,7 @@
3636
)
3737
from sqlmesh.core.test import ModelTest
3838
from sqlmesh.utils import rich as srich
39+
from sqlmesh.utils import Verbosity
3940
from sqlmesh.utils.concurrency import NodeExecutionFailedError
4041
from sqlmesh.utils.date import time_like_to_str, to_date, yesterday_ds
4142
from sqlmesh.utils.errors import (

sqlmesh/core/constants.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import os
66
import typing as t
77
from pathlib import Path
8-
from enum import IntEnum
98

109
SQLMESH = "sqlmesh"
1110
SQLMESH_PATH = Path.home() / ".sqlmesh"
@@ -92,9 +91,3 @@
9291
HYBRID = "hybrid"
9392

9493
DISABLE_SQLMESH_STATE_MIGRATION = "SQLMESH__AIRFLOW__DISABLE_STATE_MIGRATION"
95-
96-
97-
class Verbosity(IntEnum):
98-
DEFAULT = 1
99-
VERBOSE = 2
100-
VERY_VERBOSE = 3

sqlmesh/core/context.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
from sqlglot import Dialect, exp
5252
from sqlglot.helper import first
5353
from sqlglot.lineage import GraphHTML
54-
from sqlmesh.core.constants import Verbosity
54+
5555
from sqlmesh.core import analytics
5656
from sqlmesh.core import constants as c
5757
from sqlmesh.core.analytics import python_api_analytics
@@ -114,7 +114,7 @@
114114
run_tests,
115115
)
116116
from sqlmesh.core.user import User
117-
from sqlmesh.utils import UniqueKeyDict
117+
from sqlmesh.utils import UniqueKeyDict, Verbosity
118118
from sqlmesh.utils.dag import DAG
119119
from sqlmesh.utils.date import TimeLike, now_ds, to_timestamp, format_tz_datetime
120120
from sqlmesh.utils.errors import (

sqlmesh/core/test/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pathlib
44
import typing as t
55
import unittest
6-
from sqlmesh.core.constants import Verbosity
6+
77
from sqlmesh.core.engine_adapter import EngineAdapter
88
from sqlmesh.core.model import Model
99
from sqlmesh.core.test.definition import ModelTest as ModelTest, generate_test as generate_test
@@ -14,7 +14,7 @@
1414
load_model_test_file as load_model_test_file,
1515
)
1616
from sqlmesh.core.test.result import ModelTextTestResult as ModelTextTestResult
17-
from sqlmesh.utils import UniqueKeyDict
17+
from sqlmesh.utils import UniqueKeyDict, Verbosity
1818

1919
if t.TYPE_CHECKING:
2020
from sqlmesh.core.config.loader import C

sqlmesh/integrations/github/cicd/controller.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
import requests
1616
from hyperscript import Element, h
1717
from sqlglot.helper import seq_get
18-
from sqlmesh.core.constants import Verbosity
18+
1919
from sqlmesh.core import constants as c
2020
from sqlmesh.core.console import SNAPSHOT_CHANGE_CATEGORY_STR, get_console, MarkdownConsole
21-
2221
from sqlmesh.core.context import Context
2322
from sqlmesh.core.environment import Environment
2423
from sqlmesh.core.plan import Plan, PlanBuilder
@@ -31,7 +30,7 @@
3130
)
3231
from sqlmesh.core.user import User
3332
from sqlmesh.integrations.github.cicd.config import GithubCICDBotConfig
34-
from sqlmesh.utils import word_characters_only
33+
from sqlmesh.utils import word_characters_only, Verbosity
3534
from sqlmesh.utils.concurrency import NodeExecutionFailedError
3635
from sqlmesh.utils.date import now
3736
from sqlmesh.utils.errors import (

sqlmesh/integrations/llm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from langchain import LLMChain, PromptTemplate
66
from langchain.chat_models import ChatOpenAI
77

8-
from sqlmesh.core.constants import Verbosity
8+
from sqlmesh.utils import Verbosity
99
from sqlmesh.core.model import Model
1010

1111
_QUERY_PROMPT_TEMPLATE = """Given an input request, create a syntactically correct {dialect} SQL query.

sqlmesh/magics.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from IPython.core.magic_arguments import argument, magic_arguments, parse_argstring
2525
from IPython.utils.process import arg_split
2626
from rich.jupyter import JupyterRenderable
27-
from sqlmesh.core.constants import Verbosity
2827
from sqlmesh.cli.example_project import ProjectTemplate, init_example_project
2928
from sqlmesh.core import analytics
3029
from sqlmesh.core import constants as c
@@ -34,7 +33,7 @@
3433
from sqlmesh.core.dialect import format_model_expressions, parse
3534
from sqlmesh.core.model import load_sql_based_model
3635
from sqlmesh.core.test import ModelTestMetadata, get_all_model_tests
37-
from sqlmesh.utils import sqlglot_dialects, yaml
36+
from sqlmesh.utils import sqlglot_dialects, yaml, Verbosity
3837
from sqlmesh.utils.errors import MagicError, MissingContextException, SQLMeshError
3938

4039
logger = logging.getLogger(__name__)
@@ -437,17 +436,20 @@ def test(self, context: Context, line: str, test_def_raw: t.Optional[str] = None
437436
action="store_true",
438437
help="Output text differences for the rendered versions of the models and standalone audits",
439438
)
440-
@argument("--verbose", "-v", action="store_true", help="Verbose output.")
441-
@argument("--very-verbose", "-vv", action="store_true", help="Very verbose output.")
439+
@argument(
440+
"--verbose",
441+
"-v",
442+
action="count",
443+
default=0,
444+
help="Verbose output. Use -vv for very verbose.",
445+
)
442446
@line_magic
443447
@pass_sqlmesh_context
444448
def plan(self, context: Context, line: str) -> None:
445449
"""Goes through a set of prompts to both establish a plan and apply it"""
446450
args = parse_argstring(self.plan, line)
447451

448-
verbosity = Verbosity.VERBOSE if args.verbose else Verbosity.DEFAULT
449-
verbosity = Verbosity.VERY_VERBOSE if args.very_verbose else verbosity
450-
setattr(context.console, "verbosity", verbosity)
452+
setattr(context.console, "verbosity", Verbosity(args.verbose))
451453

452454
context.plan(
453455
args.environment,
@@ -968,8 +970,13 @@ def create_test(self, context: Context, line: str) -> None:
968970
type=str,
969971
help="Only run tests that match the pattern of substring.",
970972
)
971-
@argument("--verbose", "-v", action="store_true", help="Verbose output.")
972-
@argument("--very-verbose", "-vv", action="store_true", help="Very verbose output.")
973+
@argument(
974+
"--verbose",
975+
"-v",
976+
action="count",
977+
default=0,
978+
help="Verbose output. Use -vv for very verbose.",
979+
)
973980
@argument(
974981
"--preserve-fixtures",
975982
action="store_true",
@@ -981,13 +988,10 @@ def run_test(self, context: Context, line: str) -> None:
981988
"""Run unit test(s)."""
982989
args = parse_argstring(self.run_test, line)
983990

984-
verbosity = Verbosity.VERBOSE if args.verbose else Verbosity.DEFAULT
985-
verbosity = Verbosity.VERY_VERBOSE if args.very_verbose else verbosity
986-
987991
context.test(
988992
match_patterns=args.pattern,
989993
tests=args.tests,
990-
verbosity=verbosity,
994+
verbosity=Verbosity(args.verbose),
991995
preserve_fixtures=args.preserve_fixtures,
992996
)
993997

@@ -1014,18 +1018,19 @@ def audit(self, context: Context, line: str) -> None:
10141018
help="Skip the connection test.",
10151019
default=False,
10161020
)
1017-
@argument("--verbose", "-v", action="store_true", help="Verbose output.")
1018-
@argument("--very-verbose", "-vv", action="store_true", help="Very verbose output.")
1021+
@argument(
1022+
"--verbose",
1023+
"-v",
1024+
action="count",
1025+
default=0,
1026+
help="Verbose output. Use -vv for very verbose.",
1027+
)
10191028
@line_magic
10201029
@pass_sqlmesh_context
10211030
def info(self, context: Context, line: str) -> None:
10221031
"""Display SQLMesh project information."""
10231032
args = parse_argstring(self.info, line)
1024-
1025-
verbosity = Verbosity.VERBOSE if args.verbose else Verbosity.DEFAULT
1026-
verbosity = Verbosity.VERY_VERBOSE if args.very_verbose else verbosity
1027-
1028-
context.print_info(skip_connection=args.skip_connection, verbosity=verbosity)
1033+
context.print_info(skip_connection=args.skip_connection, verbosity=Verbosity(args.verbose))
10291034

10301035
@magic_arguments()
10311036
@line_magic

sqlmesh/utils/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from collections import defaultdict
1717
from contextlib import contextmanager
1818
from copy import deepcopy
19+
from enum import IntEnum
1920
from functools import lru_cache, reduce, wraps
2021
from pathlib import Path
2122

@@ -338,3 +339,11 @@ def type_is_known(d_type: t.Union[exp.DataType, exp.ColumnDef]) -> bool:
338339
def columns_to_types_all_known(columns_to_types: t.Dict[str, exp.DataType]) -> bool:
339340
"""Checks that all column types are known and not NULL."""
340341
return all(type_is_known(expression) for expression in columns_to_types.values())
342+
343+
344+
class Verbosity(IntEnum):
345+
"""Verbosity levels for SQLMesh output."""
346+
347+
DEFAULT = 0
348+
VERBOSE = 1
349+
VERY_VERBOSE = 2

0 commit comments

Comments
 (0)