diff --git a/pyproject.toml b/pyproject.toml index 4372c84861..a7380980c6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -301,3 +301,4 @@ banned-module-level-imports = [ "sqlmesh/lsp/**/*.py" = ["TID251"] "tests/lsp/**/*.py" = ["TID251"] "benchmarks/lsp*.py" = ["TID251"] +"sqlmesh/dbt/builtin.py" = ["T100"] diff --git a/sqlmesh/dbt/builtin.py b/sqlmesh/dbt/builtin.py index 49f07f597c..07edeefa2e 100644 --- a/sqlmesh/dbt/builtin.py +++ b/sqlmesh/dbt/builtin.py @@ -21,7 +21,7 @@ from sqlmesh.dbt.relation import Policy from sqlmesh.dbt.target import TARGET_TYPE_TO_CONFIG_CLASS from sqlmesh.dbt.util import DBT_VERSION -from sqlmesh.utils import AttributeDict, yaml +from sqlmesh.utils import AttributeDict, debug_mode_enabled, yaml from sqlmesh.utils.date import now from sqlmesh.utils.errors import ConfigError, MacroEvalError from sqlmesh.utils.jinja import JinjaMacroRegistry, MacroReference, MacroReturnVal @@ -316,6 +316,15 @@ def _try_literal_eval(value: str) -> t.Any: return value +def debug() -> str: + import sys + import ipdb # type: ignore + + frame = sys._getframe(3) + ipdb.set_trace(frame) + return "" + + BUILTIN_GLOBALS = { "dbt_version": version.__version__, "env_var": env_var, @@ -336,6 +345,10 @@ def _try_literal_eval(value: str) -> t.Any: "zip_strict": lambda *args: list(zip(*args)), } +# Add debug function conditionally both with dbt or sqlmesh equivalent flag +if os.environ.get("DBT_MACRO_DEBUGGING") or debug_mode_enabled(): + BUILTIN_GLOBALS["debug"] = debug + BUILTIN_FILTERS = { "as_bool": as_bool, "as_native": _try_literal_eval,