Skip to content

Commit

Permalink
Use python-dotenv instead of custom code for env vars.
Browse files Browse the repository at this point in the history
  • Loading branch information
illume committed Aug 7, 2018
1 parent c1a0a54 commit 9736751
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 25 deletions.
27 changes: 2 additions & 25 deletions pygameweb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,6 @@

# So we can use environment variables to configure things.

def load_into_environ(fname):
""" load the key value pairs in fname into the os.environ.
from dotenv import load_dotenv
load_dotenv()

Each line should have a key=value pair.
There can be comments with #.
:param fname: name of the '.env' file.
"""
import os

def as_key_value(lines):
""" Return a dict of the key value pairs.
"""
no_comments = [l.split('#')[0].rstrip() for l in lines if not l.startswith('#')]
no_empty = [l for l in no_comments if l]
kvs = [l.split('=') for l in no_empty]
no_extra_spaces = [(k.rstrip().lstrip(), v.rstrip().lstrip()) for k, v in kvs]
return no_extra_spaces

if os.path.exists(fname):
with open(fname) as lines:
for key, value in as_key_value(lines):
if key not in os.environ:
os.environ[key] = value

load_into_environ('.env')
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ ghdiff
numpy
pandas
psycopg2
python-dotenv
pyquery
pygments
pq
Expand Down

0 comments on commit 9736751

Please sign in to comment.