Skip to content

Commit d3929c6

Browse files
author
Saurabh Kumar
committed
fix(find_dotenv): it should walk up the directory from where it's called from
Fixes theskumar#24
1 parent fbcbe89 commit d3929c6

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

dotenv/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22
import os
3+
import sys
34
import warnings
45

56
from .compat import OrderedDict
@@ -125,7 +126,8 @@ def find_dotenv(filename='.env', raise_error_if_not_found=False, usecwd=False):
125126
path = os.getcwd()
126127
else:
127128
# will work for .py files
128-
path = os.path.dirname(os.path.abspath(__file__))
129+
frame_filename = sys._getframe().f_back.f_code.co_filename
130+
path = os.path.dirname(os.path.abspath(frame_filename))
129131

130132
for dirname in _walk_to_root(path):
131133
check_path = os.path.join(dirname, filename)

tests/test_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_find_dotenv():
2929
3030
Then try to automatically `find_dotenv` starting in `child4`
3131
"""
32-
tmpdir = tempfile.mkdtemp()
32+
tmpdir = os.path.realpath(tempfile.mkdtemp())
3333

3434
curr_dir = tmpdir
3535
dirs = []

0 commit comments

Comments
 (0)