Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An option to specify .env filename #73

Closed
balta2ar opened this issue Nov 2, 2018 · 6 comments
Closed

An option to specify .env filename #73

balta2ar opened this issue Nov 2, 2018 · 6 comments

Comments

@balta2ar
Copy link

balta2ar commented Nov 2, 2018

Hi. Similarly to django-configurations, it could be very convenient to be able to specify an environment filename with variables, not just to have .env hard-coded. For example, I could therefore specify a set of vars for different environments, e.g. prod.env, staging.env, and I could switch them using another env variable, e.g.:

DECOUPLE_CONFIGURATION=staging.env python program.py
@rednaks
Copy link

rednaks commented Apr 4, 2019

Hi @balta2ar while I think it's a good idea too, and thinking about the best way how to implement it, you're still can use from decouple import AutoConfig and use the search_path argument:

config = AutoConfig(search_path='./staging-env/') 

while your you have this ./stagin-env/.env

@rednaks
Copy link

rednaks commented Apr 6, 2019

Here is a proposal to support a custom config file name https://github.com/henriquebastos/python-decouple/pull/76/files

@henriquebastos
Copy link
Collaborator

I don't understand the need for this since the role purpose of decouple is to avoid having different settings layouts. The values may change on each instance, but the keys must all be the same in every environment.

Can anyone detail a concrete and real use case for this?

@pirate
Copy link

pirate commented Nov 14, 2019

Running Django tests is an example of a special case where values in .env should be ignored in favor of a different hardcoded file. e.g. we often want to swap out the entire DB configuration to use an in-memory db or a specific postgres db when testing. Granted, there are other ways to accomplish this, but being able to specify the path to an arbitrary anything.env file would make it very easy.

@hkpypy
Copy link

hkpypy commented Feb 5, 2020

I don't understand the need for this since the role purpose of decouple is to avoid having different settings layouts. The values may change on each instance, but the keys must all be the same in every environment.

Can anyone detail a concrete and real use case for this?
In every instance I could have 2 env files (.env, test.env) .env file for application and test.env file for test cases. this is the basic need.

@henriquebastos
Copy link
Collaborator

@pirate so this seems to be specific for you where your workflow is not align with decouple's design guide. No problem.

The easy way to deal with this kind of particularity is to compliment your workflow with some shell alias or makefile to link the proper file as .env prior to run a command.

For instance:

alias runtests=ln -s test.env .env && manage.py test
alias runserver=ln -s dev.env .env && manage.py runserver

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants