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

Feat: Add pyaml-env constructor PyamlEnvConstructor #23

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

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?

src/pyaml_env/constructor.py Show resolved Hide resolved
src/pyaml_env/parse_config.py Show resolved Hide resolved
@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