|
38 | 38 | from sqlmesh.core.test import ModelTestMetadata, filter_tests_by_patterns |
39 | 39 | from sqlmesh.utils import UniqueKeyDict, sys_path |
40 | 40 | from sqlmesh.utils.errors import ConfigError |
41 | | -from sqlmesh.utils.jinja import ( |
42 | | - JinjaMacroRegistry, |
43 | | - MacroExtractor, |
44 | | - SQLMESH_DBT_COMPATIBILITY_PACKAGE, |
45 | | -) |
| 41 | +from sqlmesh.utils.jinja import JinjaMacroRegistry, MacroExtractor |
46 | 42 | from sqlmesh.utils.metaprogramming import import_python_file |
47 | 43 | from sqlmesh.utils.pydantic import validation_error_message |
48 | 44 | from sqlmesh.utils.process import create_process_pool_executor |
@@ -561,7 +557,6 @@ def _load_sql_models( |
561 | 557 | signals: UniqueKeyDict[str, signal], |
562 | 558 | cache: CacheBase, |
563 | 559 | gateway: t.Optional[str], |
564 | | - loading_default_kwargs: t.Optional[t.Dict[str, t.Any]] = None, |
565 | 560 | ) -> UniqueKeyDict[str, Model]: |
566 | 561 | """Loads the sql models into a Dict""" |
567 | 562 | models: UniqueKeyDict[str, Model] = UniqueKeyDict("models") |
@@ -604,7 +599,6 @@ def _load_sql_models( |
604 | 599 | signal_definitions=signals, |
605 | 600 | default_catalog_per_gateway=self.context.default_catalog_per_gateway, |
606 | 601 | virtual_environment_mode=self.config.virtual_environment_mode, |
607 | | - **loading_default_kwargs or {}, |
608 | 602 | ) |
609 | 603 |
|
610 | 604 | with create_process_pool_executor( |
@@ -971,104 +965,3 @@ def _model_cache_entry_id(self, model_path: Path) -> str: |
971 | 965 | self._loader.context.gateway or self._loader.config.default_gateway_name, |
972 | 966 | ] |
973 | 967 | ) |
974 | | - |
975 | | - |
976 | | -class MigratedDbtProjectLoader(SqlMeshLoader): |
977 | | - @property |
978 | | - def migrated_dbt_project_name(self) -> str: |
979 | | - return self.config.variables[c.MIGRATED_DBT_PROJECT_NAME] |
980 | | - |
981 | | - def _load_scripts(self) -> t.Tuple[MacroRegistry, JinjaMacroRegistry]: |
982 | | - from sqlmesh.dbt.converter.common import infer_dbt_package_from_path |
983 | | - from sqlmesh.dbt.target import TARGET_TYPE_TO_CONFIG_CLASS |
984 | | - |
985 | | - # Store a copy of the macro registry |
986 | | - standard_macros = macro.get_registry() |
987 | | - |
988 | | - jinja_macros = JinjaMacroRegistry( |
989 | | - create_builtins_module=SQLMESH_DBT_COMPATIBILITY_PACKAGE, |
990 | | - top_level_packages=["dbt", self.migrated_dbt_project_name], |
991 | | - ) |
992 | | - extractor = MacroExtractor() |
993 | | - |
994 | | - macros_max_mtime: t.Optional[float] = None |
995 | | - |
996 | | - for path in self._glob_paths( |
997 | | - self.config_path / c.MACROS, |
998 | | - ignore_patterns=self.config.ignore_patterns, |
999 | | - extension=".py", |
1000 | | - ): |
1001 | | - if import_python_file(path, self.config_path): |
1002 | | - self._track_file(path) |
1003 | | - macro_file_mtime = self._path_mtimes[path] |
1004 | | - macros_max_mtime = ( |
1005 | | - max(macros_max_mtime, macro_file_mtime) |
1006 | | - if macros_max_mtime |
1007 | | - else macro_file_mtime |
1008 | | - ) |
1009 | | - |
1010 | | - for path in self._glob_paths( |
1011 | | - self.config_path / c.MACROS, |
1012 | | - ignore_patterns=self.config.ignore_patterns, |
1013 | | - extension=".sql", |
1014 | | - ): |
1015 | | - self._track_file(path) |
1016 | | - macro_file_mtime = self._path_mtimes[path] |
1017 | | - macros_max_mtime = ( |
1018 | | - max(macros_max_mtime, macro_file_mtime) if macros_max_mtime else macro_file_mtime |
1019 | | - ) |
1020 | | - |
1021 | | - with open(path, "r", encoding="utf-8") as file: |
1022 | | - try: |
1023 | | - package = infer_dbt_package_from_path(path) or self.migrated_dbt_project_name |
1024 | | - |
1025 | | - jinja_macros.add_macros( |
1026 | | - extractor.extract(file.read(), dialect=self.config.model_defaults.dialect), |
1027 | | - package=package, |
1028 | | - ) |
1029 | | - except Exception as e: |
1030 | | - raise ConfigError(f"Failed to load macro file: {e}", path) |
1031 | | - |
1032 | | - self._macros_max_mtime = macros_max_mtime |
1033 | | - |
1034 | | - macros = macro.get_registry() |
1035 | | - macro.set_registry(standard_macros) |
1036 | | - |
1037 | | - connection_config = self.context.connection_config |
1038 | | - # this triggers the DBT create_builtins_module to have a `target` property which is required for a bunch of DBT macros to work |
1039 | | - if dbt_config_type := TARGET_TYPE_TO_CONFIG_CLASS.get(connection_config.type_): |
1040 | | - try: |
1041 | | - jinja_macros.add_globals( |
1042 | | - { |
1043 | | - "target": dbt_config_type.from_sqlmesh( |
1044 | | - connection_config, |
1045 | | - name=self.config.default_gateway_name, |
1046 | | - ).attribute_dict() |
1047 | | - } |
1048 | | - ) |
1049 | | - except NotImplementedError: |
1050 | | - raise ConfigError(f"Unsupported dbt target type: {connection_config.type_}") |
1051 | | - |
1052 | | - return macros, jinja_macros |
1053 | | - |
1054 | | - def _load_sql_models( |
1055 | | - self, |
1056 | | - macros: MacroRegistry, |
1057 | | - jinja_macros: JinjaMacroRegistry, |
1058 | | - audits: UniqueKeyDict[str, ModelAudit], |
1059 | | - signals: UniqueKeyDict[str, signal], |
1060 | | - cache: CacheBase, |
1061 | | - gateway: t.Optional[str], |
1062 | | - loading_default_kwargs: t.Optional[t.Dict[str, t.Any]] = None, |
1063 | | - ) -> UniqueKeyDict[str, Model]: |
1064 | | - return super()._load_sql_models( |
1065 | | - macros=macros, |
1066 | | - jinja_macros=jinja_macros, |
1067 | | - audits=audits, |
1068 | | - signals=signals, |
1069 | | - cache=cache, |
1070 | | - gateway=gateway, |
1071 | | - loading_default_kwargs=dict( |
1072 | | - migrated_dbt_project_name=self.migrated_dbt_project_name, |
1073 | | - ), |
1074 | | - ) |
0 commit comments