Better detection of interactive shells and project directory - #102
Closed
andrewsmith wants to merge 3 commits into
Closed
Better detection of interactive shells and project directory#102andrewsmith wants to merge 3 commits into
andrewsmith wants to merge 3 commits into
Conversation
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.
theskumar
force-pushed
the
master
branch
2 times, most recently
from
December 16, 2018 13:18
f628767 to
f9863d3
Compare
theskumar
pushed a commit
that referenced
this pull request
Jun 2, 2019
Port of #102 from @andrewsmith closes #102
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. |
Collaborator
|
I believe this was fixed by another PR or commit. If not please open an issue about the problem or another PR. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, callingload_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!