Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use python-dotenv instead of custom code for env vars. #56

Merged
merged 1 commit into from
Aug 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
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
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