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 f420fa1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 25 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Expand Up @@ -21,7 +21,9 @@ cache: pip
python:
- '3.6'
install:
- pip install --upgrade pip
- pip install -r requirements.dev.txt
- pip install --upgrade pytest
- pip install coveralls
- pip install -e .
script: APP_SECRET_KEY=a pytest
Expand Down
27 changes: 2 additions & 25 deletions pygameweb/__init__.py
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
Expand Up @@ -18,6 +18,7 @@ ghdiff
numpy
pandas
psycopg2
python-dotenv
pyquery
pygments
pq
Expand Down

0 comments on commit f420fa1

Please sign in to comment.