Skip to content

Add method to walk up directories looking for .env - #23

Merged
theskumar merged 1 commit into
theskumar:masterfrom
isms:autofind
May 1, 2016
Merged

Add method to walk up directories looking for .env#23
theskumar merged 1 commit into
theskumar:masterfrom
isms:autofind

Conversation

@isms

@isms isms commented Apr 29, 2016

Copy link
Copy Markdown
Contributor
  • 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

- 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
@theskumar

Copy link
Copy Markdown
Owner

Thanks @isms for this thoughtful implementation, really nice work! We would need get a bit of documentation added before I can make a release.

@theskumar
theskumar merged commit 1fd40c5 into theskumar:master May 1, 2016
@theskumar

Copy link
Copy Markdown
Owner

Hi @isms, just made a new release on pypi, wondering if you check everything looks good on your end.

Thanks again for your contribution. :)

@isms

isms commented May 1, 2016

Copy link
Copy Markdown
Contributor Author

@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 .env from Jupyter notebooks.

I just tested it and it works 👍. One tiny recommendation: in the README on line 58 it says "filthy magic stack backtracking," but unlike django-dotenv we aren't doing the same kind of crazy stuff using sys._getframe(), just some plain old directory backtracking 📁

Thanks again!

@theskumar

Copy link
Copy Markdown
Owner

I've updated to docs and nice to hear this project is turning out to be useful in cookiecutter-data-science.

Best.

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

Successfully merging this pull request may close these issues.

2 participants