Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@andrewsmith
Copy link

We were using python-dotenv and noticed some problems when calling load_dotenv(), namely, that it wasn't finding the .env file in our project directory correctly. However, calling load_dotenv(find_dotenv()) worked just fine. This was failing in interactive shells and when running .py files.

I did a bit of investigation this morning and noticed two things that seemed off. These are noted in the commits below. dotenv project tests pass with py.test tests/ in CPython 2.7.10 and 3.6.4.

Cheers!

Andrew Smith added 3 commits March 16, 2018 11:57
Previously, this checked whether __file__ was defined in globals().  globals()
is tied to the current module, so this will always be defined. Fix this by
importing __main__ and asking whether it has __file__ defined. This approach is
outlined in https://stackoverflow.com/a/2356420.
The previous code relied on sys._getframe(), which is is marked as
internal and CPython-centric. Replace this with use of the standard
library 'inspect' module, which is supported in Python 2 and 3.

Additionally, only one frame up the stack was being inspected. This
fails when called within the same module, such as dotenv_values() and
load_dotenv() does. Follow the stack up until it goes outside of the
current module and use that as the reference point to start searching
for .env files from.
@coveralls
Copy link

coveralls commented Mar 16, 2018

Coverage Status

Coverage decreased (-1.8%) to 90.65% when pulling d6921b4 on andrewsmith:master into fe35be1 on theskumar:master.

@theskumar theskumar force-pushed the master branch 2 times, most recently from f628767 to f9863d3 Compare December 16, 2018 13:18
theskumar pushed a commit that referenced this pull request Jun 2, 2019
@theskumar
Copy link
Owner

This doesn't work in python < 3.5, because of this change. https://docs.python.org/3/library/inspect.html#inspect.getouterframes and the test fails with lastest master. The build failing can be seen at https://travis-ci.org/theskumar/python-dotenv/builds/540408046

I'm porting the 00cab0b via #183, but cbdf64e will probably need some more work, till we are supporting python 2.

@bbc2
Copy link
Collaborator

bbc2 commented Feb 7, 2020

I believe this was fixed by another PR or commit. If not please open an issue about the problem or another PR. Thanks!

@bbc2 bbc2 closed this Feb 7, 2020
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.

4 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.