Skip to content

Commit

Permalink
Add override-flag to dotenv_values to allow for more advanced chaining
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbergvall committed Aug 13, 2021
1 parent 1ea25f3 commit c56f00d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 4 additions & 1 deletion src/dotenv/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -361,7 +364,7 @@ def dotenv_values(
stream=stream,
verbose=verbose,
interpolate=interpolate,
override=True,
override=override,
encoding=encoding,
base_env=base_env,
).dict()

0 comments on commit c56f00d

Please sign in to comment.