From e139830158d8c40348200762e440f3ee0c3ad059 Mon Sep 17 00:00:00 2001 From: Lars Kellogg-Stedman Date: Mon, 14 Mar 2022 21:01:30 -0400 Subject: [PATCH 1/3] Fix docstring for load_dotenv The docstring for load_dotenv was missing a word, rendering it confusing. This commits modifies it for clarity. --- src/dotenv/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dotenv/main.py b/src/dotenv/main.py index 20ac61ba..b5943b20 100644 --- a/src/dotenv/main.py +++ b/src/dotenv/main.py @@ -325,7 +325,8 @@ def load_dotenv( in `.env` file. Defaults to `False`. - *encoding*: encoding to be used to read the file. - If both `dotenv_path` and `stream`, `find_dotenv()` is used to find the .env file. + If neither `dotenv_path` nor `stream` are provided, `find_dotenv()` is used + to find the .env file. """ if dotenv_path is None and stream is None: dotenv_path = find_dotenv() From 1371bb804fffbb66c2d968a9bc0f49e2a8182045 Mon Sep 17 00:00:00 2001 From: Lars Kellogg-Stedman Date: Mon, 14 Mar 2022 21:02:12 -0400 Subject: [PATCH 2/3] Return False when we do not discover any environment variables This modifies Dotenv.set_as_environment_variables to return False if we have not discovered any environment variables via either `dotenv_path` or `stream`. The return value gets passed through to `load_dotenv`, so this can be used to determine if `dotenv.load_dotenv` was able to set anything. Closes #321 --- src/dotenv/main.py | 3 +++ tests/test_main.py | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/dotenv/main.py b/src/dotenv/main.py index b5943b20..3600a4ef 100644 --- a/src/dotenv/main.py +++ b/src/dotenv/main.py @@ -87,6 +87,9 @@ def set_as_environment_variables(self) -> bool: """ Load the current dotenv as system environment variable. """ + if not self.dict(): + return False + for k, v in self.dict().items(): if k in os.environ and not self.override: continue diff --git a/tests/test_main.py b/tests/test_main.py index 364fc24d..1da8874c 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -259,8 +259,9 @@ def test_load_dotenv_no_file_verbose(): logger = logging.getLogger("dotenv.main") with mock.patch.object(logger, "info") as mock_info: - dotenv.load_dotenv('.does_not_exist', verbose=True) + result = dotenv.load_dotenv('.does_not_exist', verbose=True) + assert result is False mock_info.assert_called_once_with("Python-dotenv could not find configuration file %s.", ".does_not_exist") From 9e403852938abbc7d642621ab86088b3d8ff2355 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Sun, 5 Jun 2022 11:18:46 +0530 Subject: [PATCH 3/3] Update src/dotenv/main.py --- src/dotenv/main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/dotenv/main.py b/src/dotenv/main.py index d970f7a3..78410660 100644 --- a/src/dotenv/main.py +++ b/src/dotenv/main.py @@ -327,7 +327,6 @@ def load_dotenv( override: Whether to override the system environment variables with the variables from the `.env` file. encoding: Encoding to be used to read the file. - Returns: Bool: True if atleast one environment variable is set elese False