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

find_dotenv doesn't work as expected #24

Closed
voidlily opened this issue May 13, 2016 · 6 comments
Closed

find_dotenv doesn't work as expected #24

voidlily opened this issue May 13, 2016 · 6 comments

Comments

@voidlily
Copy link

What I did

from dotenv import find_dotenv, load_dotenv
load_dotenv(find_dotenv())

What I expected

The .env file to be loaded properly

What I got

The .env file was not found

Additional information

I print-debugged the code and found the following path when it walks up the directory tree

/usr/local/lib/python3.5/site-packages/dotenv
/usr/local/lib/python3.5/site-packages
/usr/local/lib/python3.5
/usr/local/lib
/usr/local
/usr
/

This might be from the usage of __file__ in that module.

Is this the intended behavior of find_dotenv?

@theskumar
Copy link
Owner

That's not intended behavior and sure we can use a fix. I'll have a look into it. Thanks for reporting.

@mikepqr
Copy link

mikepqr commented May 18, 2016

I see the same behaviour. Looks like find_dotenv() is broken. I tested this on both Python 2.7 and 3.5.

$ cat .env
TEST=1234
$ cat settings.py
from dotenv import find_dotenv
print(find_dotenv())
$ python settings.py

$

Based on my limited understanding, I think you want path = os.path.abspath(inspect.stack()[-1][1]) here.

@theskumar theskumar reopened this May 19, 2016
@theskumar
Copy link
Owner

@voidlily @WilliamsMJ I've added a fix for the .env finding logic. It now starts finding from the python file from where it's called, then move up the directory till /.

You can try it out by installing from latest master.

pip install --upgrade https://github.com/theskumar/python-dotenv/archive/master.zip

If things look, I'll make a new release on pypi.

Cheers,

@mikepqr
Copy link

mikepqr commented May 19, 2016

Works for me 👍

$ cat .env
TEST=1234
$ cat settings.py
from dotenv import find_dotenv
print(find_dotenv())
$ python settings.py
/Users/mike/tmp/dotenv/.env
$

@isms
Copy link
Contributor

isms commented May 25, 2016

@voidlily good catch! @theskumar that one is on me -- oops 😞

Just tested again using new master and it works for me.

@theskumar
Copy link
Owner

@isms no worries!

I've made released v0.5.1 🎉 which contains this fix.

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

4 participants