sqlmesh 0.194.2.dev8__py3-none-any.whl → 0.194.2.dev10__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
sqlmesh/_version.py CHANGED
@@ -17,5 +17,5 @@ __version__: str
17
17
  __version_tuple__: VERSION_TUPLE
18
18
  version_tuple: VERSION_TUPLE
19
19
 
20
- __version__ = version = '0.194.2.dev8'
21
- __version_tuple__ = version_tuple = (0, 194, 2, 'dev8')
20
+ __version__ = version = '0.194.2.dev10'
21
+ __version_tuple__ = version_tuple = (0, 194, 2, 'dev10')
sqlmesh/cli/main.py CHANGED
@@ -191,6 +191,7 @@ def init(
191
191
  help="The SQL dialect to render the query as.",
192
192
  )
193
193
  @click.option("--no-format", is_flag=True, help="Disable fancy formatting of the query.")
194
+ @opt.format_options
194
195
  @click.pass_context
195
196
  @error_handler
196
197
  @cli_analytics
@@ -203,6 +204,7 @@ def render(
203
204
  expand: t.Optional[t.Union[bool, t.Iterable[str]]] = None,
204
205
  dialect: t.Optional[str] = None,
205
206
  no_format: bool = False,
207
+ **format_kwargs: t.Any,
206
208
  ) -> None:
207
209
  """Render a model's query, optionally expanding referenced models."""
208
210
  rendered = ctx.obj.render(
@@ -213,7 +215,17 @@ def render(
213
215
  expand=expand,
214
216
  )
215
217
 
216
- sql = rendered.sql(pretty=True, dialect=ctx.obj.config.dialect if dialect is None else dialect)
218
+ format_config = ctx.obj.config_for_node(model).format
219
+ format_kwargs = {
220
+ **format_config.generator_options,
221
+ **{k: v for k, v in format_kwargs.items() if v is not None},
222
+ }
223
+
224
+ sql = rendered.sql(
225
+ pretty=True,
226
+ dialect=ctx.obj.config.dialect if dialect is None else dialect,
227
+ **format_kwargs,
228
+ )
217
229
  if no_format:
218
230
  print(sql)
219
231
  else:
@@ -264,55 +276,23 @@ def evaluate(
264
276
  help="Transpile project models to the specified dialect.",
265
277
  )
266
278
  @click.option(
267
- "--append-newline",
268
- is_flag=True,
269
- help="Include a newline at the end of each file.",
270
- default=None,
271
- )
272
- @click.option(
273
- "--no-rewrite-casts",
274
- is_flag=True,
275
- help="Preserve the existing casts, without rewriting them to use the :: syntax.",
276
- default=None,
277
- )
278
- @click.option(
279
- "--normalize",
279
+ "--check",
280
280
  is_flag=True,
281
- help="Whether or not to normalize identifiers to lowercase.",
281
+ help="Whether or not to check formatting (but not actually format anything).",
282
282
  default=None,
283
283
  )
284
284
  @click.option(
285
- "--pad",
286
- type=int,
287
- help="Determines the pad size in a formatted string.",
288
- )
289
- @click.option(
290
- "--indent",
291
- type=int,
292
- help="Determines the indentation size in a formatted string.",
293
- )
294
- @click.option(
295
- "--normalize-functions",
296
- type=str,
297
- help="Whether or not to normalize all function names. Possible values are: 'upper', 'lower'",
298
- )
299
- @click.option(
300
- "--leading-comma",
285
+ "--rewrite-casts/--no-rewrite-casts",
301
286
  is_flag=True,
302
- help="Determines whether or not the comma is leading or trailing in select expressions. Default is trailing.",
287
+ help="Rewrite casts to use the :: syntax.",
303
288
  default=None,
304
289
  )
305
290
  @click.option(
306
- "--max-text-width",
307
- type=int,
308
- help="The max number of characters in a segment before creating new lines in pretty mode.",
309
- )
310
- @click.option(
311
- "--check",
291
+ "--append-newline",
312
292
  is_flag=True,
313
- help="Whether or not to check formatting (but not actually format anything).",
314
- default=None,
293
+ help="Include a newline at the end of each file.",
315
294
  )
295
+ @opt.format_options
316
296
  @click.pass_context
317
297
  @error_handler
318
298
  @cli_analytics
@@ -320,9 +300,6 @@ def format(
320
300
  ctx: click.Context, paths: t.Optional[t.Tuple[str, ...]] = None, **kwargs: t.Any
321
301
  ) -> None:
322
302
  """Format all SQL models and audits."""
323
- if kwargs.pop("no_rewrite_casts", None):
324
- kwargs["rewrite_casts"] = False
325
-
326
303
  if not ctx.obj.format(**{k: v for k, v in kwargs.items() if v is not None}, paths=paths):
327
304
  ctx.exit(1)
328
305
 
sqlmesh/cli/options.py CHANGED
@@ -1,6 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import os
4
+ import typing as t
4
5
 
5
6
  import click
6
7
 
@@ -54,3 +55,38 @@ verbose = click.option(
54
55
  count=True,
55
56
  help="Verbose output. Use -vv for very verbose output.",
56
57
  )
58
+
59
+
60
+ def format_options(func: t.Callable) -> t.Callable:
61
+ """Decorator to add common format options to CLI commands."""
62
+ func = click.option(
63
+ "--normalize",
64
+ is_flag=True,
65
+ help="Whether or not to normalize identifiers to lowercase.",
66
+ )(func)
67
+ func = click.option(
68
+ "--pad",
69
+ type=int,
70
+ help="Determines the pad size in a formatted string.",
71
+ )(func)
72
+ func = click.option(
73
+ "--indent",
74
+ type=int,
75
+ help="Determines the indentation size in a formatted string.",
76
+ )(func)
77
+ func = click.option(
78
+ "--normalize-functions",
79
+ type=str,
80
+ help="Whether or not to normalize all function names. Possible values are: 'upper', 'lower'",
81
+ )(func)
82
+ func = click.option(
83
+ "--leading-comma",
84
+ is_flag=True,
85
+ help="Determines whether or not the comma is leading or trailing in select expressions. Default is trailing.",
86
+ )(func)
87
+ func = click.option(
88
+ "--max-text-width",
89
+ type=int,
90
+ help="The max number of characters in a segment before creating new lines in pretty mode.",
91
+ )(func)
92
+ return func
sqlmesh/dbt/manifest.py CHANGED
@@ -21,7 +21,14 @@ from dbt.config import Profile, Project, RuntimeConfig
21
21
  from dbt.config.profile import read_profile
22
22
  from dbt.config.renderer import DbtProjectYamlRenderer, ProfileRenderer
23
23
  from dbt.parser.manifest import ManifestLoader
24
- from dbt.parser.sources import merge_freshness
24
+
25
+ try:
26
+ from dbt.parser.sources import merge_freshness # type: ignore[attr-defined]
27
+ except ImportError:
28
+ # merge_freshness was renamed to merge_source_freshness in dbt 1.10
29
+ # ref: https://github.com/dbt-labs/dbt-core/commit/14fc39a76ff4830cdf2fcbe73f57ca27db500018#diff-1f09db95588f46879a83378c2a86d6b16b7cdfcaddbfe46afc5d919ee5e9a4d9R430
30
+ from dbt.parser.sources import merge_source_freshness as merge_freshness # type: ignore[no-redef,attr-defined]
31
+
25
32
  from dbt.tracking import do_not_track
26
33
 
27
34
  from sqlmesh.core import constants as c
sqlmesh/magics.py CHANGED
@@ -93,6 +93,43 @@ def pass_sqlmesh_context(func: t.Callable) -> t.Callable:
93
93
  return wrapper
94
94
 
95
95
 
96
+ def format_arguments(func: t.Callable) -> t.Callable:
97
+ """Decorator to add common format arguments to magic commands."""
98
+ func = argument(
99
+ "--normalize",
100
+ action="store_true",
101
+ help="Whether or not to normalize identifiers to lowercase.",
102
+ default=None,
103
+ )(func)
104
+ func = argument(
105
+ "--pad",
106
+ type=int,
107
+ help="Determines the pad size in a formatted string.",
108
+ )(func)
109
+ func = argument(
110
+ "--indent",
111
+ type=int,
112
+ help="Determines the indentation size in a formatted string.",
113
+ )(func)
114
+ func = argument(
115
+ "--normalize-functions",
116
+ type=str,
117
+ help="Whether or not to normalize all function names. Possible values are: 'upper', 'lower'",
118
+ )(func)
119
+ func = argument(
120
+ "--leading-comma",
121
+ action="store_true",
122
+ help="Determines whether or not the comma is leading or trailing in select expressions. Default is trailing.",
123
+ default=None,
124
+ )(func)
125
+ func = argument(
126
+ "--max-text-width",
127
+ type=int,
128
+ help="The max number of characters in a segment before creating new lines in pretty mode.",
129
+ )(func)
130
+ return func
131
+
132
+
96
133
  @magics_class
97
134
  class SQLMeshMagics(Magics):
98
135
  @property
@@ -579,23 +616,39 @@ class SQLMeshMagics(Magics):
579
616
  )
580
617
  @argument("--dialect", type=str, help="SQL dialect to render.")
581
618
  @argument("--no-format", action="store_true", help="Disable fancy formatting of the query.")
619
+ @format_arguments
582
620
  @line_magic
583
621
  @pass_sqlmesh_context
584
622
  def render(self, context: Context, line: str) -> None:
585
623
  """Renders a model's query, optionally expanding referenced models."""
586
624
  context.refresh()
587
- args = parse_argstring(self.render, line)
625
+ render_opts = vars(parse_argstring(self.render, line))
626
+ model = render_opts.pop("model")
627
+ dialect = render_opts.pop("dialect", None)
588
628
 
589
629
  query = context.render(
590
- args.model,
591
- start=args.start,
592
- end=args.end,
593
- execution_time=args.execution_time,
594
- expand=args.expand,
630
+ model,
631
+ start=render_opts.pop("start", None),
632
+ end=render_opts.pop("end", None),
633
+ execution_time=render_opts.pop("execution_time", None),
634
+ expand=render_opts.pop("expand", False),
595
635
  )
596
636
 
597
- sql = query.sql(pretty=True, dialect=args.dialect or context.config.dialect)
598
- if args.no_format:
637
+ no_format = render_opts.pop("no_format", False)
638
+
639
+ format_config = context.config_for_node(model).format
640
+ format_options = {
641
+ **format_config.generator_options,
642
+ **{k: v for k, v in render_opts.items() if v is not None},
643
+ }
644
+
645
+ sql = query.sql(
646
+ pretty=True,
647
+ dialect=context.config.dialect if dialect is None else dialect,
648
+ **format_options,
649
+ )
650
+
651
+ if no_format:
599
652
  context.console.log_status_update(sql)
600
653
  else:
601
654
  context.console.show_sql(sql)
@@ -853,55 +906,24 @@ class SQLMeshMagics(Magics):
853
906
  help="Transpile project models to the specified dialect.",
854
907
  )
855
908
  @argument(
856
- "--append-newline",
857
- action="store_true",
858
- help="Whether or not to append a newline to the end of the file.",
859
- default=None,
860
- )
861
- @argument(
862
- "--no-rewrite-casts",
863
- action="store_true",
864
- help="Whether or not to preserve the existing casts, without rewriting them to use the :: syntax.",
865
- default=None,
866
- )
867
- @argument(
868
- "--normalize",
909
+ "--check",
869
910
  action="store_true",
870
- help="Whether or not to normalize identifiers to lowercase.",
911
+ help="Whether or not to check formatting (but not actually format anything).",
871
912
  default=None,
872
913
  )
873
914
  @argument(
874
- "--pad",
875
- type=int,
876
- help="Determines the pad size in a formatted string.",
877
- )
878
- @argument(
879
- "--indent",
880
- type=int,
881
- help="Determines the indentation size in a formatted string.",
882
- )
883
- @argument(
884
- "--normalize-functions",
885
- type=str,
886
- help="Whether or not to normalize all function names. Possible values are: 'upper', 'lower'",
887
- )
888
- @argument(
889
- "--leading-comma",
915
+ "--append-newline",
890
916
  action="store_true",
891
- help="Determines whether or not the comma is leading or trailing in select expressions. Default is trailing.",
917
+ help="Include a newline at the end of the output.",
892
918
  default=None,
893
919
  )
894
920
  @argument(
895
- "--max-text-width",
896
- type=int,
897
- help="The max number of characters in a segment before creating new lines in pretty mode.",
898
- )
899
- @argument(
900
- "--check",
921
+ "--no-rewrite-casts",
901
922
  action="store_true",
902
- help="Whether or not to check formatting (but not actually format anything).",
923
+ help="Preserve the existing casts, without rewriting them to use the :: syntax.",
903
924
  default=None,
904
925
  )
926
+ @format_arguments
905
927
  @line_magic
906
928
  @pass_sqlmesh_context
907
929
  def format(self, context: Context, line: str) -> bool:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqlmesh
3
- Version: 0.194.2.dev8
3
+ Version: 0.194.2.dev10
4
4
  Summary: Next-generation data transformation framework
5
5
  Author-email: "TobikoData Inc." <engineering@tobikodata.com>
6
6
  License: Apache License
@@ -1,14 +1,14 @@
1
1
  sqlmesh/__init__.py,sha256=QjwaamJIdW7voXoS880yAx7tHm-Im4_mqGA-XJgafos,7631
2
- sqlmesh/_version.py,sha256=MYOxoUqpiJh2ziCzXdBKBf1qyxYKD-ugg9-fBHa0StY,528
3
- sqlmesh/magics.py,sha256=ysPC5ohXpgQ8IHQPwtQtwGoVypmVq_YBlm1noUueDIw,40448
2
+ sqlmesh/_version.py,sha256=wzA1cY-yQIYIuRp-_eGOlbKshvMeUvabC1O2j0Qyo84,530
3
+ sqlmesh/magics.py,sha256=d7udR_sieKWzp_YXNFPA2O173xDCqk6u9CIKB7Skb2c,41206
4
4
  sqlmesh/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  sqlmesh/cicd/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  sqlmesh/cicd/bot.py,sha256=2zlbn-DXkqQzr3lA0__IGU4XaIfXBXBKLWXNI2DRJX8,759
7
7
  sqlmesh/cicd/config.py,sha256=mpgkisSBBovlNrNZir2unT8Wes6b38RW2UsU_o4e8vY,109
8
8
  sqlmesh/cli/__init__.py,sha256=MAXAyO7isbyM-PaSdFjkJNcjn32WjOl0XzxT5gvp_vo,1690
9
9
  sqlmesh/cli/example_project.py,sha256=QAFQbw_kzqn30GLTthqsuWXbFDBpX8W6RsCgQ-jx65M,9308
10
- sqlmesh/cli/main.py,sha256=CM97CwI_DkrcE6TfJOwpiAaheYDr8WE7Tl-8asgV-Yw,33845
11
- sqlmesh/cli/options.py,sha256=aC_L5WnMScKzMU55BD1Y-8R-QzqCkPSYrlCI-payHRA,1333
10
+ sqlmesh/cli/main.py,sha256=wo5_057ofKgB6D32bl6zBCNZDKwBSXrZv5IzGpRnB3o,33179
11
+ sqlmesh/cli/options.py,sha256=-4ZclMIeIg8tghLowtmQNmpEFlm0QtOVEh40NqRdFHA,2499
12
12
  sqlmesh/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
13
  sqlmesh/core/_typing.py,sha256=e1f7xO2aZCy38M_3VoDy-XI3shyd99-IFctgIFSgXWM,497
14
14
  sqlmesh/core/console.py,sha256=pMIkBjaigneVqGkoGxOKVmT423RPfbDKX8TQ8D1SzpU,153466
@@ -131,7 +131,7 @@ sqlmesh/dbt/column.py,sha256=Kvj_N3D_QegcoNQG7VqRiqy-FRfupud-6ilhlykBOgE,1873
131
131
  sqlmesh/dbt/common.py,sha256=g4PAL-sEdlnfb_zT-WW3xh-oamyCUoK8dUiDEMVwDWI,7804
132
132
  sqlmesh/dbt/context.py,sha256=dxClM-G1IeMbP0v5yxC_va8QNU-uKghW2dBlSZHJOk0,10331
133
133
  sqlmesh/dbt/loader.py,sha256=U95hDUGgWgsC6clhMubMO0jfaID6_ivHu7pfUUSt26I,15576
134
- sqlmesh/dbt/manifest.py,sha256=gg3BrN-ypOns4afa8JT0H-GuZKqWaR4We8oSh2sK_5Q,24200
134
+ sqlmesh/dbt/manifest.py,sha256=HP2RszGfYZw0VVO3Ifndkxg1PUQpTGvan_tHzMqPqjE,24619
135
135
  sqlmesh/dbt/model.py,sha256=FgQpl8pUNOnihGUo5PYdqOqqOX3XtfDHX3xEJc-CVC4,25782
136
136
  sqlmesh/dbt/package.py,sha256=IBBQueVB4_4C9tIk0-GUL-O2uibNxXu6W2a4AeHHcOU,4322
137
137
  sqlmesh/dbt/profile.py,sha256=Fz2c0dJNN0xBgYEogCIKBTByjNvlA2BVBzOLQCfdEfM,3788
@@ -282,7 +282,7 @@ sqlmesh/utils/pydantic.py,sha256=I898jAFqa3qU6lG2uPpRebVFncOUo8ZrLWM_R3K3DHU,116
282
282
  sqlmesh/utils/rich.py,sha256=BpB47G0-JcU41LkGkeGKroexj4NOV5fox4-GOIXPgIc,3545
283
283
  sqlmesh/utils/windows.py,sha256=r7Yin4WEwbvH7sKA3hOJtRsclmscNuBeCklCfVPvtQs,611
284
284
  sqlmesh/utils/yaml.py,sha256=np-WVcwmwsKghCgAj1OBBMsK1SXSRn4wR-H37cGiFr8,2282
285
- sqlmesh-0.194.2.dev8.dist-info/licenses/LICENSE,sha256=OlMefUjgWJdULtf84BLW0AZZcY8DwdgQqb_1j2862j8,11346
285
+ sqlmesh-0.194.2.dev10.dist-info/licenses/LICENSE,sha256=OlMefUjgWJdULtf84BLW0AZZcY8DwdgQqb_1j2862j8,11346
286
286
  web/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
287
287
  web/client/dist/index.html,sha256=w71qWSLmp-xwmVJO8m41k8Rtni3iZlF0hmhiTr-NeCI,5472
288
288
  web/client/dist/assets/Audits-sYYNn2gO.js,sha256=zSAKkif2kU0JuPH05xjNYITNPmsbDlvLKUc2-orr8AY,1041
@@ -400,8 +400,8 @@ web/server/api/endpoints/models.py,sha256=ud-lRwriyI_OYg9tZchrBgeiXELiRTLNEodraf
400
400
  web/server/api/endpoints/modules.py,sha256=8hqqgonGay_mJmpCw0IdbjsPhWlQH2VLdKAqha-myac,468
401
401
  web/server/api/endpoints/plan.py,sha256=OYuQ_4dgbhG9ibTcX1a8mvYgH3ANxw9Fhbb4wg6QWqc,9222
402
402
  web/server/api/endpoints/table_diff.py,sha256=SCy3-pr5x6bEEiOaZGCDbiHQhpgxwmnz3Acqa2Ie6jI,2090
403
- sqlmesh-0.194.2.dev8.dist-info/METADATA,sha256=tK9qWjCZK77Sl2v-JkKP6G8Eo9SPxoCa4lVjVdKHzQw,26690
404
- sqlmesh-0.194.2.dev8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
405
- sqlmesh-0.194.2.dev8.dist-info/entry_points.txt,sha256=pIYKtg-u-uO7BK_Y0qrdmfyj0bYrcMc3Xiqr5WE3VFk,121
406
- sqlmesh-0.194.2.dev8.dist-info/top_level.txt,sha256=bspjo5vjELQkuN0qKuTFIbsrUt3Zeo8D2mlKeHG1LdE,12
407
- sqlmesh-0.194.2.dev8.dist-info/RECORD,,
403
+ sqlmesh-0.194.2.dev10.dist-info/METADATA,sha256=HPbnhVzcwgmGJ2daUhcdsGHRK2vXuFxBNrNgI-uA-tg,26691
404
+ sqlmesh-0.194.2.dev10.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
405
+ sqlmesh-0.194.2.dev10.dist-info/entry_points.txt,sha256=pIYKtg-u-uO7BK_Y0qrdmfyj0bYrcMc3Xiqr5WE3VFk,121
406
+ sqlmesh-0.194.2.dev10.dist-info/top_level.txt,sha256=bspjo5vjELQkuN0qKuTFIbsrUt3Zeo8D2mlKeHG1LdE,12
407
+ sqlmesh-0.194.2.dev10.dist-info/RECORD,,