forked from sendgrid/python-http-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
36 lines (30 loc) · 1.09 KB
/
config.py
File metadata and controls
36 lines (30 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""Configuration for library"""
import os
class Config(object):
"""Definition of configuration options"""
def __init__(self, base_path=None):
"""Allow variables assigned in .env available using
os.environ.get('VAR_NAME')
:param base_path: The path to your .env config file
:type base_path: string
"""
if base_path:
base_path = base_path
else:
# By default, choose the parent directory
base_path = os.path.join(os.path.dirname(__file__), os.pardir)
# Setup the environment variables found in .env
if os.path.exists('{0}/.env'.format(base_path)):
env_file = open('{0}/.env'.format(base_path))
for line in env_file:
var = line.strip().split('=')
if len(var) == 2:
os.environ[var[0]] = var[1]
env_file.close()
self._local_path_to_env = '{0}/.env'.format(base_path)
@property
def local_path_to_env(self):
"""
:return: string
"""
return self._local_path_to_env