Skip to content

Commit

Permalink
fix: attributes are not overrided in other files than .env.template. …
Browse files Browse the repository at this point in the history
…problem of lower case keys
  • Loading branch information
rv2931 committed Feb 26, 2024
1 parent 56950eb commit 614deb4
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions bloom/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def extract_values(filename:str,config:dict,allow_extend:bool=True):
if(len(split)==2):
# if extracted key already exist in config OR if allowed to add new keys to config
# Then adding/updating key/value
if split[0] in config.keys() or allow_extend == True:
if split[0].lower() in config.keys() or allow_extend == True:
config[split[0].lower()]=split[1]
return config

Expand All @@ -47,20 +47,20 @@ def __init__(self,*arg, **args):

# Extract .env.${app_env} and override existing values
# We restrict extracted keys to the keys already existing in .env.template
file_to_process=Path(os.path.dirname(__file__)).joinpath(f"../.env.{self.app_env}")
file_to_process=Path(os.path.dirname(__file__)).joinpath(f"../.env.{config['app_env']}")
if os.path.isfile(file_to_process): extract_values(file_to_process,config,allow_extend=False)

# Extract .env.${app_env}.local and override existing values
# We restrict extracted keys to the keys already existing in .env.template
file_to_process=Path(os.path.dirname(__file__)).joinpath(f"../.env.{self.app_env}.local")
file_to_process=Path(os.path.dirname(__file__)).joinpath(f"../.env.{config['app_env']}.local")
if os.path.isfile(file_to_process): extract_values(file_to_process,config,allow_extend=False)

# Now all .env.* files has been merged, we write the cumulated result to .env
# .env is for compliance with docker/docker-compose standard
file_to_process=Path(os.path.dirname(__file__)).joinpath(f"../.env")
f = open(file_to_process, "w")
f.truncate(0)
f.write("# This file was generated automaticaly by bloom.config\n# Don't modify values directly here\n# Use .env.* files instead then restart application")
f.write("# This file was generated automaticaly by bloom.config\n# Don't modify values directly here\n# Use .env.* files instead then restart application\n")
for k,v in config.items():
f.write(f"{k}={v}\n")
f.close()
Expand Down

0 comments on commit 614deb4

Please sign in to comment.