From c56f00d15cb6bc69aa92b52d133bf85ecd85559c Mon Sep 17 00:00:00 2001 From: John Bergvall Date: Fri, 13 Aug 2021 16:44:39 +0200 Subject: [PATCH] Add override-flag to dotenv_values to allow for more advanced chaining --- CHANGELOG.md | 2 ++ README.md | 3 ++- src/dotenv/main.py | 5 ++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba13ab39..b022ac46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - Add support to use a custom dict instead of os.environ for variable interpolating when calling `dotenv_values` (by [@johnbergvall]) +- Add override-flag to `dotenv_values` to allow for more advanced + chaining of env-files (#73 #186 by [@johnbergvall]) ## [0.19.0] - 2021-07-24 diff --git a/README.md b/README.md index 15637668..37402e10 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,8 @@ deploy_env = { 'VERSION': '1.5', } env = dotenv_values('.env.deployment01', base_env={ - **dotenv_values('.env.base', base_env=deploy_env), + # override=False to ignore local file overrides in interpolations: + **dotenv_values('.env.base', override=False, base_env=deploy_env), **deploy_env, }) subprocess.call( diff --git a/src/dotenv/main.py b/src/dotenv/main.py index fbda7f40..08b6ae2b 100644 --- a/src/dotenv/main.py +++ b/src/dotenv/main.py @@ -337,6 +337,7 @@ def dotenv_values( dotenv_path: Union[str, _PathLike, None] = None, stream: Optional[IO[str]] = None, verbose: bool = False, + override: bool = True, interpolate: bool = True, encoding: Optional[str] = "utf-8", base_env: Mapping[str, Optional[str]] = os.environ, @@ -348,6 +349,8 @@ def dotenv_values( - *stream*: `StringIO` object with .env content, used if `dotenv_path` is `None`. - *verbose*: whether to output a warning the .env file is missing. Defaults to `False`. + - *override*: whether to override the system environment/`base_env` variables with + the variables in `.env` file. Defaults to `True` as opposed to `load_dotenv`. - *encoding*: encoding to be used to read the file. - *base_env*: dict with initial environment. Defaults to os.environ @@ -361,7 +364,7 @@ def dotenv_values( stream=stream, verbose=verbose, interpolate=interpolate, - override=True, + override=override, encoding=encoding, base_env=base_env, ).dict()