Error using multiple configs files from different folders, having a default file (not merged)
See original GitHub issueI need to read from multiple settings file and also a common setting file (aka defaults). To do so i’m setting the ENV variable to the two file paths
os.environ['SETTINGS_FILE_FOR_DYNACONF'] = '<abs_path>/config/default.toml, <abs_path>/config1/settings.toml'
default.toml
[development]
VAR_DFT = "default_dev"
[production]
VAR_DFT = "default_prod"
settings.toml
[development]
VAR1 = 'config1_dev'
[production]
VAR1 = 'config1_prod'
import os
from dynaconf import settings
from config import __file__ as config_file
from config1 import __file__ as config1_file
from config2 import __file__ as config2_file
default = os.path.join(os.path.dirname(config_file), 'default-settings.toml')
f1 = os.path.join(os.path.dirname(config1_file), 'settings.toml')
f2 = os.path.join(os.path.dirname(config2_file), 'settings.toml')
print('using config 1')
os.environ['SETTINGS_FILE_FOR_DYNACONF'] = "{}, {}".format(default, f1)
print('development')
settings.setenv('development')
print(settings.VAR_DFT) #no error
print(settings.VAR1) #gives me error
print('changing to production')
settings.setenv('production')
print(settings.VAR1)
print('----')
print('using config 2')
os.environ['SETTINGS_FILE_FOR_DYNACONF'] = "{},{}".format(default, f2)
print('development')
settings.setenv('development')
print(settings.VAR1)
print('changing to production')
settings.setenv('production')
print(settings.VAR1)
It gives me error AttributeError: 'Settings' object has no attribute 'VAR1'
trying to access VAR1… so the more specific setting and not the default…
It seems like it’s not merging the two configurations.
Is it possibile, am i totally on the wrong path?
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Git merge error - different config files in different branches
First, let's cover this part: Am I using a good method for maintaining different config files in both branches? (I've just seen this...
Read more >When using multiple docker-compose.yml files from different ...
yml . The error message is something like: ERROR: build path ~/myproj/myservice/ either does not exist, is not accessible, or is not a...
Read more >Import data from a folder with multiple files (Power Query)
Locate the folder containing the files you want to combine, and then select Open. A list of all the files in the folder...
Read more >How to merge all (text) files in a directory into one?
Though beware the list of files is not sorted and hidden files are included. ... To get round this, either write the merged...
Read more >Organizing Cluster Access Using kubeconfig Files - Kubernetes
Use kubeconfig files to organize information about clusters, users, namespaces, and authentication mechanisms. The kubectl command-line tool ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Very good example! From your comment it wasn’t so clear, but the code seems to accomplish my needs! As always you made an excellent tool.
A bit tricky is only the INCLUDES env variable format, maybe a
yaml
format doesn’t need brackets and single quotes… but i don’t know.so probably a more python style reload/env/include would be useful… are you agree?
@fabiosoft you are right about the formatting, that is useful to environment variables complex lists but not for simple values.
I pushed the changes in #183
path/to/path.toml
or separate it by;
or,
settings.load_file(path="/path/to/file.toml")