forked from repo-mirrors/sqlfluff
Add "target_path" configuration to the dbt templater (#6423)
Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com> Co-authored-by: Greg Finley <gregory.finley@gmail.com>
This commit is contained in:
@@ -56,6 +56,7 @@ class DbtConfigArgs:
|
||||
profiles_dir: Optional[str] = None
|
||||
profile: Optional[str] = None
|
||||
target: Optional[str] = None
|
||||
target_path: Optional[str] = None
|
||||
threads: int = 1
|
||||
single_threaded: bool = False
|
||||
# dict in 1.5.x onwards, json string before.
|
||||
@@ -282,6 +283,7 @@ class DbtTemplater(JinjaTemplater):
|
||||
project_dir=self.project_dir,
|
||||
profiles_dir=self.profiles_dir,
|
||||
profile=self._get_profile(),
|
||||
target_path=self._get_target_path(),
|
||||
vars=cli_vars,
|
||||
threads=1,
|
||||
),
|
||||
@@ -293,6 +295,7 @@ class DbtTemplater(JinjaTemplater):
|
||||
profiles_dir=self.profiles_dir,
|
||||
profile=self._get_profile(),
|
||||
target=self._get_target(),
|
||||
target_path=self._get_target_path(),
|
||||
vars=cli_vars,
|
||||
threads=1,
|
||||
)
|
||||
@@ -435,6 +438,12 @@ class DbtTemplater(JinjaTemplater):
|
||||
(self.templater_selector, self.name, "target")
|
||||
)
|
||||
|
||||
def _get_target_path(self):
|
||||
"""Get a dbt target path from the configuration."""
|
||||
return self.sqlfluff_config.get_section(
|
||||
(self.templater_selector, self.name, "target_path")
|
||||
)
|
||||
|
||||
def _get_cli_vars(self) -> dict:
|
||||
cli_vars = self.sqlfluff_config.get_section(
|
||||
(self.templater_selector, self.name, "context")
|
||||
|
||||
@@ -48,6 +48,7 @@ def test__templater_dbt_profiles_dir_expanded(dbt_templater):
|
||||
"profiles_dir": "~/.dbt",
|
||||
"profile": "default",
|
||||
"target": "dev",
|
||||
"target_path": "target",
|
||||
}
|
||||
},
|
||||
},
|
||||
@@ -59,6 +60,7 @@ def test__templater_dbt_profiles_dir_expanded(dbt_templater):
|
||||
)
|
||||
assert dbt_templater._get_profile() == "default"
|
||||
assert dbt_templater._get_target() == "dev"
|
||||
assert dbt_templater._get_target_path() == "target"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
Reference in New Issue
Block a user