-
-
Notifications
You must be signed in to change notification settings - Fork 316
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
Improve documentation for read_env() #88
Comments
Also, the documentation mentions a "filthy magic stack backtracking" in order to "find manage.py and then find the dotenv". It should be specified more in detail what this means. When you have a two-level hierarchy then the mysite
+-- mysite
| +-- settings.py
+-- .env # not found by Env.read_env() in mysite.settings |
IMO less problematic will be to inform user that they can point path for BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
env = environ.Env(
DEBUG=(bool, False),
)
environ.Env.read_env('{}/.env'.format(BASE_DIR)) |
I'd suggest to use |
True my bad 😄 |
That really gave me some wtf moments. After reading that wording regarding "filthy magic" I was literally expect it to magically find that my .env is located at the same directory as manage.py which was one level up from settings.py. |
The read_env documentation currently states: > If not given a path to a dotenv path, does filthy magic stack > backtracking to find manage.py and then find the dotenv. Based on joke2k#88, it appears that this behavior is rather fragile. To improve this, I think the package should document that read_env expects you to provide a path. If one is not provided, it will attempt to use the BASE_DIR constant from the django settings module. If an ImportError is encountered while it attempts to do this, read_env will assume there's no .env file to be found, log an info message to that effect, and continue on. fixes: joke2k#88
The read_env documentation currently states: > If not given a path to a dotenv path, does filthy magic stack > backtracking to find manage.py and then find the dotenv. Based on joke2k#88, it appears that this behavior is rather fragile. To improve this, I think the package should document that read_env expects you to provide a path. If one is not provided, it will attempt to use the BASE_DIR constant from the django settings module. If an ImportError is encountered while it attempts to do this, read_env will assume there's no .env file to be found, log an info message to that effect, and continue on. fixes: joke2k#88
The readme briefly mentions
read_env()
, however it wasn't until reading the source that the following became apparent:.env
file are overridden by any that already existed in the environment (I think this is handy, but isn't immediately obvious)read_env()
also takes an overrides listread_env()
updatesos.environ
directly, rather than just that particularEnv
instance (someone not realising this was intentional is what caused Why read_env reads everything to os.environ? #66 to be filed)It would be great to mention the above in the readme. If I get a chance to open a PR I will, but it may not be soon, so if anyone wants to do so in the meantime, go ahead :-)
The text was updated successfully, but these errors were encountered: