Add method to walk up directories looking for .env - #23
Conversation
- Add `find_dotenv` method that will try to find a .env file by (a) guessing where to start using `__file__` or the working directory -- allowing this to work in non-file contexts such as IPython notebooks and the REPL, and then (b) walking up the dir- ectory tree looking for the specified file -- called `.env` by default. This is a bit like the "filthy magic" employed by django-dotenv[1] to serve the same purpose, and allows the user to write `load_dotenv(find_dotenv())` in many contexts. - Add test for new function [1] https://github.com/jpadilla/django-dotenv/blob/master/dotenv.py#L44-L46
|
Thanks @isms for this thoughtful implementation, really nice work! We would need get a bit of documentation added before I can make a release. |
|
Hi @isms, just made a new release on pypi, wondering if you check everything looks good on your end. Thanks again for your contribution. :) |
|
@theskumar: Awesome! Thanks for the fast turnaround -- we're using your package in https://github.com/drivendata/cookiecutter-data-science and this will make it a lot easier for people to use I just tested it and it works 👍. One tiny recommendation: in the README on line 58 it says "filthy magic stack backtracking," but unlike Thanks again! |
|
I've updated to docs and nice to hear this project is turning out to be useful in cookiecutter-data-science. Best. |
find_dotenvmethod that will try to find a .env file by(a) guessing where to start using
__file__or the workingdirectory -- allowing this to work in non-file contexts such as
IPython notebooks and the REPL, and then (b) walking up the dir-
ectory tree looking for the specified file -- called
.envbydefault. This is a bit like the "filthy magic" employed by
django-dotenv[1] to serve the same purpose, and allows the user
to write
load_dotenv(find_dotenv())in many contexts.[1] https://github.com/jpadilla/django-dotenv/blob/master/dotenv.py#L44-L46