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

Context managers for setting configurations. #75

Open
gitkief opened this issue Feb 22, 2025 · 0 comments
Open

Context managers for setting configurations. #75

gitkief opened this issue Feb 22, 2025 · 0 comments

Comments

@gitkief
Copy link

gitkief commented Feb 22, 2025

What?

I am bit confused with the naming and the purpose of the context managers.

dewret/src/dewret/core.py

Lines 223 to 249 in 68ef970

@contextmanager
def set_configuration(
**kwargs: Unpack[ConstructConfigurationTypedDict],
) -> Iterator[ContextVar[GlobalConfiguration]]:
"""Sets the construct-time configuration.
This is a context manager, so that a setting can be temporarily overridden and automatically restored.
"""
with _set_configuration() as CONFIGURATION:
for key, value in kwargs.items():
setattr(CONFIGURATION.get().construct, key, value)
yield CONFIGURATION
@contextmanager
def set_render_configuration(
kwargs: dict[str, RawType],
) -> Iterator[ContextVar[GlobalConfiguration]]:
"""Sets the render-time configuration.
This is a context manager, so that a setting can be temporarily overridden and automatically restored.
Returns: the yielded global configuration ContextVar.
"""
with _set_configuration() as CONFIGURATION:
CONFIGURATION.get().render.update(**kwargs)
yield CONFIGURATION

The docstring of the set_configuration manager states it sets construct-time configuration. And then there is the set_render_configuation which I guess should set "renderer" related configuration?

Ideas

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

No branches or pull requests

1 participant