Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make flow style of yaml dump configurable #1075

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions omegaconf/omegaconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,21 +746,33 @@ def update(
assert False

@staticmethod
def to_yaml(cfg: Any, *, resolve: bool = False, sort_keys: bool = False) -> str:
def to_yaml(
cfg: Any,
*,
resolve: bool = False,
sort_keys: bool = False,
default_flow_style: Optional[bool] = False
) -> str:
"""
returns a yaml dump of this config object.

:param cfg: Config object, Structured Config type or instance
:param resolve: if True, will return a string with the interpolations resolved, otherwise
interpolations are preserved
:param sort_keys: If True, will print dict keys in sorted order. default False.
:param default_flow_style: Set default_flow_style option for PyYAML's yaml.dump().
Choices:
- False: Always use block style for collections
- True: Always use flow style
- None: Use block style for nested collections, otherwise use flow style
default False.
:return: A string containing the yaml representation.
"""
cfg = _ensure_container(cfg)
container = OmegaConf.to_container(cfg, resolve=resolve, enum_to_str=True)
return yaml.dump( # type: ignore
container,
default_flow_style=False,
default_flow_style=default_flow_style,
allow_unicode=True,
sort_keys=sort_keys,
Dumper=get_omega_conf_dumper(),
Expand Down