Skip to content

Commit 0db0af5

Browse files
authored
fix: python model macros (#3435)
1 parent 4662acd commit 0db0af5

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

examples/sushi/macros/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from sqlmesh import macro
2+
3+
4+
@macro()
5+
def noop(context):
6+
return "SELECT 1"

examples/sushi/models/waiters.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
kind=dict(name=ModelKindName.EMBEDDED),
1313
owner="jen",
1414
cron="@daily",
15+
pre_statements=["@noop()"],
1516
)
1617
def entrypoint(evaluator: MacroEvaluator) -> exp.Select:
1718
"""

sqlmesh/core/model/definition.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,6 +1871,7 @@ def create_python_model(
18711871
depends_on=depends_on,
18721872
entrypoint=entrypoint,
18731873
python_env=python_env,
1874+
macros=macros,
18741875
jinja_macros=jinja_macros,
18751876
module_path=module_path,
18761877
variables=variables,

tests/integrations/jupyter/test_magics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,15 +550,15 @@ def test_info(notebook, sushi_context, convert_all_html_output_to_text, get_all_
550550
assert len(output.outputs) == 6
551551
assert convert_all_html_output_to_text(output) == [
552552
"Models: 17",
553-
"Macros: 6",
553+
"Macros: 7",
554554
"",
555555
"Connection:\n type: duckdb\n concurrent_tasks: 1\n register_comments: true\n pre_ping: false\n extensions: []\n connector_config: {}",
556556
"Test Connection:\n type: duckdb\n concurrent_tasks: 1\n register_comments: true\n pre_ping: false\n extensions: []\n connector_config: {}",
557557
"Data warehouse connection succeeded",
558558
]
559559
assert get_all_html_output(output) == [
560560
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Models: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">17</span></pre>",
561-
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Macros: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">6</span></pre>",
561+
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Macros: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">7</span></pre>",
562562
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>",
563563
'<pre style="white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,\'DejaVu Sans Mono\',consolas,\'Courier New\',monospace">Connection: type: duckdb concurrent_tasks: <span style="color: #008080; text-decoration-color: #008080; font-weight: bold">1</span> register_comments: true pre_ping: false extensions: <span style="font-weight: bold">[]</span> connector_config: <span style="font-weight: bold">{}</span></pre>',
564564
'<pre style="white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,\'DejaVu Sans Mono\',consolas,\'Courier New\',monospace">Test Connection: type: duckdb concurrent_tasks: <span style="color: #008080; text-decoration-color: #008080; font-weight: bold">1</span> register_comments: true pre_ping: false extensions: <span style="font-weight: bold">[]</span> connector_config: <span style="font-weight: bold">{}</span></pre>',

0 commit comments

Comments
 (0)