Skip to content

Commit

Permalink
fix: python model macros (#3435)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobymao authored Nov 27, 2024
1 parent 4662acd commit 0db0af5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions examples/sushi/macros/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from sqlmesh import macro


@macro()
def noop(context):
return "SELECT 1"
1 change: 1 addition & 0 deletions examples/sushi/models/waiters.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
kind=dict(name=ModelKindName.EMBEDDED),
owner="jen",
cron="@daily",
pre_statements=["@noop()"],
)
def entrypoint(evaluator: MacroEvaluator) -> exp.Select:
"""
Expand Down
1 change: 1 addition & 0 deletions sqlmesh/core/model/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -1871,6 +1871,7 @@ def create_python_model(
depends_on=depends_on,
entrypoint=entrypoint,
python_env=python_env,
macros=macros,
jinja_macros=jinja_macros,
module_path=module_path,
variables=variables,
Expand Down
4 changes: 2 additions & 2 deletions tests/integrations/jupyter/test_magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,15 +550,15 @@ def test_info(notebook, sushi_context, convert_all_html_output_to_text, get_all_
assert len(output.outputs) == 6
assert convert_all_html_output_to_text(output) == [
"Models: 17",
"Macros: 6",
"Macros: 7",
"",
"Connection:\n type: duckdb\n concurrent_tasks: 1\n register_comments: true\n pre_ping: false\n extensions: []\n connector_config: {}",
"Test Connection:\n type: duckdb\n concurrent_tasks: 1\n register_comments: true\n pre_ping: false\n extensions: []\n connector_config: {}",
"Data warehouse connection succeeded",
]
assert get_all_html_output(output) == [
"<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>",
"<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>",
"<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>",
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>",
'<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>',
'<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>',
Expand Down

0 comments on commit 0db0af5

Please sign in to comment.