python-dependency-injector/examples/providers/configuration/configuration_env_interpolation_os_default.py
Roman Mogylatov ef049daae5
463 Config environment variables interpolation required and nones (#467)
* Make prototype with enterpolation before parsing

* Add test for option.from_yaml() with missing env not required

* Make some cosmetic changes to _resolve_config_env_markers()

* Add test for option.from_ini() missing envs not required

* Skip schema test cause it requires internet connection

* Add tests for .from_yaml() for config and config option

* Add tests for .from_ini() for config and config option

* Add example for os.environ.setdefault() and envs interpolation

* Add/update docs on environment variables interpolation

* Update changelog
2021-06-24 16:00:36 +03:00

20 lines
448 B
Python

"""`Configuration` provider values loading example."""
import os
from dependency_injector import containers, providers
class Container(containers.DeclarativeContainer):
config = providers.Configuration()
if __name__ == '__main__':
os.environ.setdefault('ENV_VAR', 'default value')
container = Container()
container.config.from_yaml('config-with-env-var.yml')
assert container.config.section.option() == 'default value'