Skip to content

Commit a936a67

Browse files
committed
Re-added black magic features to the read_dotenv to move to drop-in backward compatibility.
1 parent 3c487fb commit a936a67

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# django-dotenv-rw
22

3-
Forked from the simpler [django-dotenv](https://github.com/jacobian/django-dotenv). Removes black magic, changes a few things, adds remote .env file management capabilities. Works as a drop-in replacement for django-dotenv (if you weren't using the black magic trick).
3+
Forked from awesome but simpler [django-dotenv](https://github.com/jacobian/django-dotenv). Removes black magic, makes loading .env in settings.py easier, adds remote .env file management capabilities. Works as a drop-in replacement for django-dotenv.
44

55
[foreman](https://github.com/ddollar/foreman) reads from `.env`. `manage.py`
66
doesn't. Let's fix that.
77

8-
[heroku config](https://devcenter.heroku.com/articles/config-vars)Lets you add/delete env variables on your remote server from your local command line. django-dotenv-rw when used with fabric lets you do the same ```heroku config:set DJANGO_ENV="PRODUCTION" ``` becomes ```fab config:set,DJANGO_ENV,PRODUCTION```
8+
[heroku config](https://devcenter.heroku.com/articles/config-vars) Lets you add/delete env variables on your remote server from your local command line. django-dotenv-rw when used with fabric lets you do the same ```heroku config:set DJANGO_ENV="PRODUCTION" ``` becomes ```fab config:set,DJANGO_ENV,PRODUCTION```
99

1010
## Installation
1111

1212
```
1313
pip install pip install git+ssh://git@github.com/tedtieken/django-dotenv-rw.git
1414
```
1515

16-
## Usage: loading settins from a .env file into your django environment
16+
## Usage: loading settings from a .env file into your django environment
1717

1818
Option 1 (suggested): Near the top of `settings.py`. Add:
1919

dotenv.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,20 @@ def load_dotenv(dotenv_path):
1515
return True
1616

1717

18-
def read_dotenv(dotenv_path):
18+
def read_dotenv(dotenv_path=None):
19+
"""
20+
Prior name of load_dotenv function.
21+
22+
Deprecated and pending removal
23+
24+
If not given a path to a dotenv path, does filthy magic stack backtracking
25+
to find manage.py and then find the dotenv.
26+
"""
1927
warnings.warn("read_dotenv deprecated, use load_dotenv instead")
28+
if dotenv_path is None:
29+
warnings.warn("read_dotenv without an explicit path is deprecated and will be removed soon")
30+
frame = sys._getframe()
31+
dotenv_path = os.path.join(os.path.dirname(frame.f_back.f_code.co_filename), '.env')
2032
return load_dotenv(dotenv_path)
2133

2234

0 commit comments

Comments
 (0)