Skip to content

Conversation

@dougppaz
Copy link

Simple way to add !ENV constructor to a pyyaml loader.

from yaml import Loader
from pyaml_env import  PyamlEnvConstructor

PyamlEnvConstructor.add_to_loader_class(loader_class=Loader)
# or
PyamlEnvConstructor.add_to_loader_class(
  loader_class=Loader,
  tag=custom_tag,
  sep=custom_sep,
  default_value=custom_default_value,
  raise_if_na=True
)

Motivation: a pyaml loader can have multiple custom constructors and many any ways to load a YAML content.

@mkaranasou mkaranasou self-requested a review March 15, 2022 13:35
@mkaranasou mkaranasou self-assigned this Mar 15, 2022
Copy link
Owner

@mkaranasou mkaranasou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍, thanks for the addition! Besides the one comment for the relative imports, do you think it would be beneficial to add any tests for your change?

@olegvg
Copy link

olegvg commented May 19, 2023

Hi, @dougppaz @mkaranasou
It would be great to merge this PR despite the insufficiency of test coverage eventually. I've found this PR helpful with pydantic_yaml, which is becoming aligned with the 12-factor methodology.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants