question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error using multiple configs files from different folders, having a default file (not merged)

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
fabiosoftcommented, Apr 28, 2019

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.

os.environ["INCLUDES_FOR_DYNACONF"] = "['{}']".format(f1)  #"['config1/settings.toml']"

so probably a more python style reload/env/include would be useful… are you agree?

0reactions
rochacbrunocommented, Apr 29, 2019

@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

  • Now you can pass only the string filename as path/to/path.toml or separate it by ; or ,
  • You can still pass a toml-like list
  • You can use programmatically calling settings.load_file(path="/path/to/file.toml")
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found