Код: Выделить всё
# dynaconf_example.py
from dynaconf import Dynaconf
settings = Dynaconf(
settings_files=['dynaconf_example.toml'],
environments=True,
env_switcher='EXAMPLE_ENV',
)
Код: Выделить всё
# dynaconf_example.toml
[default]
# this doesn't seem to matter
# dynaconf_merge = true
[nonprod]
# this doesn't seem to matter
# dynaconf_merge = true
[prod]
# this doesn't seem to matter
# dynaconf_merge = true
[default.google]
domain = 'example.org'
[nonprod.google]
domain = 'nonprod.example.org'
[prod.google]
domain = 'prod.example.org'
# this doesn't seem to matter
#[default.google.calendar]
#dynaconf_merge = true
#calendar_ids = []
[nonprod.google.calendar]
calendar_ids = ['a', 'b']
[prod.google.calendar]
calendar_ids = ['c', 'd']
[default.carrot]
google = '@get google'
[default.celery.google]
domain = '@get google.domain'
[default.celery.google.calendar]
calendar_ids = '@get google.calendar.calendar_ids'
[default.onion.google]
domain = '@get google.domain'
calendar.calendar_ids = '@get google.calendar.calendar_ids'
Код: Выделить всё
$ EXAMPLE_ENV=nonprod dynaconf -i dynaconf_example.settings get carrot|jq -C .
{
"google": {
"calendar": {
"calendar_ids": [
"a",
"b"
]
},
"domain": "nonprod.example.org"
}
}
Код: Выделить всё
$ EXAMPLE_ENV=nonprod dynaconf -i dynaconf_example.settings get celery|jq -C .
{
"google": {
"calendar": {
"calendar_ids": {
"calendar_ids": [
"a",
"b"
]
}
},
"domain": "nonprod.example.org"
}
}
Код: Выделить всё
$ EXAMPLE_ENV=nonprod dynaconf -i dynaconf_example.settings get onion|jq -C .
{
"google": {
"calendar": {
"calendar_ids": {
"calendar_ids": [
"a",
"b"
]
}
},
"domain": "nonprod.example.org"
}
}
(Возможно, это связано: у меня были аналогичные проблемы с промежуточным dict/map/container со значениями, загруженными из файла .py, который был реализован для использования importlib_resources ; мне удалось обойти их, потому что результирующее значение было строкой, поэтому я мог получить нужное значение, используя @format {this.x.y.z} . Это не работает для списков; в итоге я получаю список в строке.)