Skip to content

Commit

Permalink
feat: better default str dumping for multiline strings in dbt yamls
Browse files Browse the repository at this point in the history
  • Loading branch information
z3z1ma committed Jan 4, 2025
1 parent 80a3663 commit afca0c6
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/dbt_osmosis/core/osmosis.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def create_yaml_instance(
indent_mapping: int = 2,
indent_sequence: int = 4,
indent_offset: int = 2,
width: int = 800,
width: int = 100,
preserve_quotes: bool = True,
default_flow_style: bool = False,
encoding: str = "utf-8",
Expand All @@ -330,6 +330,14 @@ def create_yaml_instance(
y.preserve_quotes = preserve_quotes
y.default_flow_style = default_flow_style
y.encoding = encoding

def str_representer(dumper: t.Any, data: t.Any) -> t.Any:
if len(data.splitlines()) > 1: # check for multiline string
return dumper.represent_scalar("tag:yaml.org,2002:str", data, style="|")
return dumper.represent_scalar("tag:yaml.org,2002:str", data)

y.representer.add_representer(str, str_representer)

logger.debug(":notebook: YAML instance created => %s", y)
return y

Expand Down

0 comments on commit afca0c6

Please sign in to comment.