From c506e173adf9bf75289f3e3bdea2492cab581121 Mon Sep 17 00:00:00 2001 From: maxkoryukov <maxkoryukov@yandex.ru> Date: Fri, 26 May 2017 20:22:52 +0500 Subject: [PATCH 1/3] Disable ".env not found" warning by default --- dotenv/main.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dotenv/main.py b/dotenv/main.py index ceac3fad..fcc0e0b6 100644 --- a/dotenv/main.py +++ b/dotenv/main.py @@ -16,12 +16,13 @@ def decode_escaped(escaped): return __escape_decoder(escaped)[0] -def load_dotenv(dotenv_path): +def load_dotenv(dotenv_path, verbose=False): """ Read a .env file and load into os.environ. """ if not os.path.exists(dotenv_path): - warnings.warn("Not loading %s - it doesn't exist." % dotenv_path) + if verbose: + warnings.warn("Not loading %s - it doesn't exist." % dotenv_path) return None for k, v in dotenv_values(dotenv_path).items(): os.environ.setdefault(k, v) From e3f33e8d518859f6107ad6c641fb18e46e028e76 Mon Sep 17 00:00:00 2001 From: maxkoryukov <maxkoryukov@yandex.ru> Date: Fri, 26 May 2017 20:27:29 +0500 Subject: [PATCH 2/3] Mention VERBOSE option in readme --- README.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.rst b/README.rst index 370828d6..e560b56c 100644 --- a/README.rst +++ b/README.rst @@ -49,6 +49,9 @@ Add the following code to your ``settings.py`` dotenv_path = join(dirname(__file__), '.env') load_dotenv(dotenv_path) + # OR, the same with increased verbosity: + load_dotenv(dotenv_path, verbose=True) + Alternatively, you can use ``find_dotenv()`` method that will try to find a ``.env`` file by (a) guessing where to start using ``__file__`` or the working directory -- allowing this to work in non-file contexts such as IPython notebooks From 311f56cf524a9e2b38a65f210170e4e631778b35 Mon Sep 17 00:00:00 2001 From: maxkoryukov <maxkoryukov@yandex.ru> Date: Fri, 26 May 2017 20:35:25 +0500 Subject: [PATCH 3/3] Fix tests for `load_dotenv` with new verbose option --- tests/test_core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_core.py b/tests/test_core.py index 29f0f9a3..8e9d3f0a 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -10,7 +10,7 @@ def test_warns_if_file_does_not_exist(): with warnings.catch_warnings(record=True) as w: - load_dotenv('.does_not_exist') + load_dotenv('.does_not_exist', verbose=True) assert len(w) == 1 assert w[0].category is UserWarning