Skip to content

Commit

Permalink
Rename variable yaml to yaml_format (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
kokorin authored Sep 17, 2024
1 parent 7b1a6ef commit 26f82c8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ project:
```yaml
vars:
dbt-pumpkin:
yaml:
yaml_format:
# indent of properties in a map, default 2
indent: 2
# offset of items in a list, default 0
Expand Down
11 changes: 9 additions & 2 deletions dbt_pumpkin/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,19 @@ def _parse_project_yml(self) -> dict[str, any]:
return self._yaml.load(project_yml_path)

def detect_yaml_format(self) -> YamlFormat | None:
pumpkin_var = self._parse_project_yml().get("vars", {}).get("dbt-pumpkin", {})
pumpkin_var = self._parse_project_yml().get("vars", {}).get("dbt-pumpkin")
if pumpkin_var is None:
return None
if not isinstance(pumpkin_var, dict):
msg = "YAML property is not an object: vars.dbt-pumpkin"
raise PumpkinError(msg)

yaml_format = pumpkin_var.get("yaml")
yaml_format = pumpkin_var.get("yaml_format")

if not yaml_format and "yaml" in pumpkin_var:
yaml_format = pumpkin_var.get("yaml")
logger.warning("Variable 'yaml' was renamed to 'yaml_format'.")

if not yaml_format:
logger.info("No YAML format set in DBT project vars, using default")
return None
Expand Down
41 changes: 39 additions & 2 deletions tests/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,24 @@ def test_detect_yaml_format_none():
profile: test_pumpkin
vars:
dbt-pumpkin:
yaml: null
yaml_format: null
""",
}
)
)
assert loader.detect_yaml_format() is None


def test_detect_yaml_format_absent():
loader = mock_loader(
mock_project(
files={
"dbt_project.yml": """\
name: test_pumpkin
version: "0.1.0"
profile: test_pumpkin
vars:
dbt-pumpkin:
""",
}
)
Expand All @@ -623,7 +640,7 @@ def test_detect_yaml_format_all_fields():
profile: test_pumpkin
vars:
dbt-pumpkin:
yaml:
yaml_format:
indent: 2
offset: 2
max_width: 140
Expand All @@ -636,6 +653,26 @@ def test_detect_yaml_format_all_fields():


def test_detect_yaml_format_indent_offset():
loader = mock_loader(
mock_project(
files={
"dbt_project.yml": """\
name: test_pumpkin
version: "0.1.0"
profile: test_pumpkin
vars:
dbt-pumpkin:
yaml_format:
indent: 2
offset: 2
""",
}
)
)
assert loader.detect_yaml_format() == YamlFormat(indent=2, offset=2)


def test_detect_yaml_format_backward_compatibility():
loader = mock_loader(
mock_project(
files={
Expand Down

0 comments on commit 26f82c8

Please sign in to comment.