Skip to content

Commit 19520c2

Browse files
committed
Allow user to specify runtime via env var
1 parent 5eaa09d commit 19520c2

4 files changed

Lines changed: 37 additions & 35 deletions

File tree

sqlmesh/__init__.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,19 @@ def get(cls) -> RuntimeEnv:
6464
6565
Unlike the rich implementation we try to split out by notebook type instead of treating it all as Jupyter.
6666
"""
67+
runtime_env_var = os.getenv("SQLMESH_RUNTIME_ENVIRONMENT")
68+
if runtime_env_var:
69+
runtime_env_var = runtime_env_var.lower().strip().replace(" ", "").replace("-", "_")
70+
runtime_env_var = "non_interactive" if runtime_env_var == "ci" else runtime_env_var
71+
runtime_env_var = "debugger" if "debug" in runtime_env_var else runtime_env_var
72+
try:
73+
return RuntimeEnv(runtime_env_var)
74+
except ValueError:
75+
valid_values = [f'"{member.value}"' for member in RuntimeEnv] + ['"ci"']
76+
raise ValueError(
77+
f"Invalid SQLMESH_RUNTIME_ENVIRONMENT value: {runtime_env_var}. Must be one of {', '.join(valid_values)}."
78+
)
79+
6780
try:
6881
shell = get_ipython() # type: ignore
6982
if os.getenv("DATABRICKS_RUNTIME_VERSION"):
@@ -78,11 +91,7 @@ def get(cls) -> RuntimeEnv:
7891
if debug_mode_enabled():
7992
return RuntimeEnv.DEBUGGER
8093

81-
if (
82-
is_cicd_environment()
83-
or not is_interactive_environment()
84-
or str_to_bool(os.environ.get("SQLMESH_NON_INTERACTIVE_TERMINAL", "false"))
85-
):
94+
if is_cicd_environment() or not is_interactive_environment():
8695
return RuntimeEnv.NON_INTERACTIVE
8796

8897
return RuntimeEnv.TERMINAL

sqlmesh/core/console.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2850,13 +2850,13 @@ def show_environment_difference_summary(
28502850
)
28512851
return
28522852

2853-
self._print(f"**Summary of differences from `{context_diff.environment}`:**\n")
2853+
self._print(f"\n**Summary of differences from `{context_diff.environment}`:**")
28542854

28552855
if context_diff.has_requirement_changes:
2856-
self._print(f"Requirements:\n{context_diff.requirements_diff()}")
2856+
self._print(f"\nRequirements:\n{context_diff.requirements_diff()}")
28572857

28582858
if context_diff.has_environment_statements_changes and not no_diff:
2859-
self._print("[bold]Environment statements:\n")
2859+
self._print("\nEnvironment statements:\n")
28602860
for _, diff in context_diff.environment_statements_diff(
28612861
include_python_env=not context_diff.is_new_environment
28622862
):

tests/integrations/github/cicd/test_integration.py

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -287,15 +287,14 @@ def test_merge_pr_has_non_breaking_change(
287287
assert GithubCheckStatus(prod_plan_preview_checks_runs[1]["status"]).is_in_progress
288288
assert GithubCheckStatus(prod_plan_preview_checks_runs[2]["status"]).is_completed
289289
assert GithubCheckConclusion(prod_plan_preview_checks_runs[2]["conclusion"]).is_success
290-
expected_prod_plan_summary = """**Summary of differences from `prod`:**
291-
290+
expected_prod_plan_summary = """\n**Summary of differences from `prod`:**
292291
293292
**Directly Modified:**
294293
- `sushi.waiter_revenue_by_day`
295294
```diff
296-
---
295+
---
297296
298-
+++
297+
+++
299298
300299
@@ -16,7 +16,8 @@
301300
@@ -484,15 +483,14 @@ def test_merge_pr_has_non_breaking_change_diff_start(
484483
assert GithubCheckStatus(prod_plan_preview_checks_runs[2]["status"]).is_completed
485484
assert GithubCheckConclusion(prod_plan_preview_checks_runs[2]["conclusion"]).is_success
486485
assert prod_plan_preview_checks_runs[2]["output"]["title"] == "Prod Plan Preview"
487-
expected_prod_plan = """**Summary of differences from `prod`:**
488-
486+
expected_prod_plan = """\n**Summary of differences from `prod`:**
489487
490488
**Directly Modified:**
491489
- `sushi.waiter_revenue_by_day`
492490
```diff
493-
---
491+
---
494492
495-
+++
493+
+++
496494
497495
@@ -16,7 +16,8 @@
498496
@@ -992,15 +990,14 @@ def test_no_merge_since_no_deploy_signal(
992990
assert GithubCheckStatus(prod_plan_preview_checks_runs[1]["status"]).is_in_progress
993991
assert GithubCheckStatus(prod_plan_preview_checks_runs[2]["status"]).is_completed
994992
assert GithubCheckConclusion(prod_plan_preview_checks_runs[2]["conclusion"]).is_success
995-
expected_prod_plan = """**Summary of differences from `prod`:**
996-
993+
expected_prod_plan = """\n**Summary of differences from `prod`:**
997994
998995
**Directly Modified:**
999996
- `sushi.waiter_revenue_by_day`
1000997
```diff
1001-
---
998+
---
1002999
1003-
+++
1000+
+++
10041001
10051002
@@ -16,7 +16,8 @@
10061003
@@ -1173,15 +1170,14 @@ def test_no_merge_since_no_deploy_signal_no_approvers_defined(
11731170
assert GithubCheckStatus(prod_plan_preview_checks_runs[1]["status"]).is_in_progress
11741171
assert GithubCheckStatus(prod_plan_preview_checks_runs[2]["status"]).is_completed
11751172
assert GithubCheckConclusion(prod_plan_preview_checks_runs[2]["conclusion"]).is_success
1176-
expected_prod_plan = """**Summary of differences from `prod`:**
1177-
1173+
expected_prod_plan = """\n**Summary of differences from `prod`:**
11781174
11791175
**Directly Modified:**
11801176
- `sushi.waiter_revenue_by_day`
11811177
```diff
1182-
---
1178+
---
11831179
1184-
+++
1180+
+++
11851181
11861182
@@ -16,7 +16,8 @@
11871183
@@ -1343,15 +1339,14 @@ def test_deploy_comment_pre_categorized(
13431339
assert GithubCheckStatus(prod_plan_preview_checks_runs[1]["status"]).is_in_progress
13441340
assert GithubCheckStatus(prod_plan_preview_checks_runs[2]["status"]).is_completed
13451341
assert GithubCheckConclusion(prod_plan_preview_checks_runs[2]["conclusion"]).is_success
1346-
expected_prod_plan = """**Summary of differences from `prod`:**
1347-
1342+
expected_prod_plan = """\n**Summary of differences from `prod`:**
13481343
13491344
**Directly Modified:**
13501345
- `sushi.waiter_revenue_by_day`
13511346
```diff
1352-
---
1347+
---
13531348
1354-
+++
1349+
+++
13551350
13561351
@@ -16,7 +16,8 @@
13571352
@@ -1682,15 +1677,14 @@ def test_overlapping_changes_models(
16821677
assert GithubCheckStatus(prod_plan_preview_checks_runs[1]["status"]).is_in_progress
16831678
assert GithubCheckStatus(prod_plan_preview_checks_runs[2]["status"]).is_completed
16841679
assert GithubCheckConclusion(prod_plan_preview_checks_runs[2]["conclusion"]).is_success
1685-
expected_prod_plan_summary = """**Summary of differences from `prod`:**
1686-
1680+
expected_prod_plan_summary = """\n**Summary of differences from `prod`:**
16871681
16881682
**Directly Modified:**
16891683
- `sushi.customers`
16901684
```diff
1691-
---
1685+
---
16921686
1693-
+++
1687+
+++
16941688
16951689
@@ -25,7 +25,8 @@
16961690
@@ -1877,8 +1871,7 @@ def test_pr_delete_model(
18771871
== """<table><thead><tr><th colspan="3">PR Environment Summary</th></tr><tr><th>Model</th><th>Change Type</th><th>Dates Loaded</th></tr></thead><tbody><tr><td>"memory"."sushi"."top_waiters"</td><td>Breaking</td><td>REMOVED</td></tr></tbody></table>"""
18781872
)
18791873

1880-
expected_prod_plan_summary = """**Summary of differences from `prod`:**
1881-
1874+
expected_prod_plan_summary = """\n**Summary of differences from `prod`:**
18821875
18831876
**Removed Models:**
18841877
- `sushi.top_waiters`

tests/integrations/jupyter/test_magics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ def test_run_dag(
324324
"'Evaluating models ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100.0% • 18/18"
325325
)
326326
assert not output.stderr
327-
assert len(output.outputs) == 2
327+
assert len(output.outputs) == 6
328328
assert convert_all_html_output_to_text(output) == [
329329
"✔ Model batches executed",
330330
"Run finished for environment 'prod'",

0 commit comments

Comments
 (0)