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

Improves Warning messaging #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 5 additions & 2 deletions envparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def cast(cls, value, cast=str, subcast=None):
url = shortcut(urlparse.urlparse)

@staticmethod
def read_envfile(path=None, **overrides):
def read_envfile(path=None, traversed_paths=[], **overrides):
"""
Read a .env file (line delimited KEY=VALUE) into os.environ.

Expand All @@ -183,6 +183,8 @@ def read_envfile(path=None, **overrides):
with open(path, 'r') as f:
content = f.read()
except getattr(__builtins__, 'FileNotFoundError', IOError):
# Append the path we tried (and failed) to load to a tracking list
traversed_paths.append(path)
logger.debug('envfile not found at %s, looking in parent dir.',
path)
filedir, filename = os.path.split(path)
Expand All @@ -192,7 +194,8 @@ def read_envfile(path=None, **overrides):
Env.read_envfile(path, **overrides)
else:
# Reached top level directory.
warnings.warn('Could not any envfile.')
output_paths = " ".join(traversed_paths)
warnings.warn('Could not load any envfile via path(s): %s' % output_paths)
return

logger.debug('Reading environment variables from: %s', path)
Expand Down