Skip to content

Commit 9af2189

Browse files
committed
Read an existing .sqlfluff config
1 parent 68e4c25 commit 9af2189

File tree

1 file changed

+19
-5
lines changed
  • data_pipelines_cli/cli_commands

1 file changed

+19
-5
lines changed

data_pipelines_cli/cli_commands/lint.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pathlib
22
import tempfile
33
from configparser import ConfigParser
4-
from typing import List
4+
from typing import Any, List
55

66
import click
77
import yaml
@@ -48,13 +48,27 @@ def _get_source_tests_paths() -> List[pathlib.Path]:
4848
return list(map(lambda dir_name: pathlib.Path.cwd().joinpath(dir_name), dir_names))
4949

5050

51+
def _insert_into_config_section(config: ConfigParser, section: str, key: str, value: Any) -> None:
52+
if section not in config:
53+
config[section] = {}
54+
config[section][key] = value
55+
56+
5157
def _create_temporary_sqlfluff_config(env: str) -> ConfigParser:
58+
sqlfluff_config_path = pathlib.Path.cwd().joinpath(".sqlfluff")
5259
config = ConfigParser()
53-
config["sqlfluff"] = {"templater": "dbt"}
54-
config["sqlfluff:templater:dbt"] = {
55-
"profiles_dir": str(generate_profiles_yml(env, copy_config_dir=True).absolute())
56-
}
60+
if sqlfluff_config_path.exists():
61+
config.read(sqlfluff_config_path)
62+
63+
_insert_into_config_section(config, "sqlfluff", "templater", "dbt")
64+
_insert_into_config_section(
65+
config,
66+
"sqlfluff:templater:dbt",
67+
"profiles_dir",
68+
str(generate_profiles_yml(env, copy_config_dir=True).absolute()),
69+
)
5770
config["sqlfluff:templater:dbt:context"] = read_dbt_vars_from_configs(env)
71+
5872
return config
5973

6074

0 commit comments

Comments
 (0)