Skip to content

Commit 16f2bda

Browse files
committed
Update spacing and docs
1 parent c715d19 commit 16f2bda

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this
66
project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased] - 2025-06-24
9+
10+
- Add support for disabling of `load_dotenv()` using `PYTHON_DOTENV_DISABLED` env var.
11+
812
## [1.1.1] - 2025-06-24
913

10-
## Fixed
14+
### Fixed
1115

1216
* CLI: Ensure `find_dotenv` work reliably on python 3.13 by [@theskumar] in [#563](https://github.com/theskumar/python-dotenv/pull/563)
1317
* CLI: revert the use of execvpe on Windows by [@wrongontheinternet] in [#566](https://github.com/theskumar/python-dotenv/pull/566)

src/dotenv/main.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@
2121
logger = logging.getLogger(__name__)
2222

2323

24+
def _load_dotenv_disabled() -> bool:
25+
"""
26+
Determine if dotenv loading has been disabled.
27+
"""
28+
if "PYTHON_DOTENV_DISABLED" not in os.environ:
29+
return False
30+
value = os.environ["PYTHON_DOTENV_DISABLED"].casefold()
31+
return value in {"1", "true", "t", "yes", "y"}
32+
33+
2434
def with_warn_for_invalid_lines(mappings: Iterator[Binding]) -> Iterator[Binding]:
2535
for mapping in mappings:
2636
if mapping.error:
@@ -349,11 +359,14 @@ def load_dotenv(
349359
.env file with it's default parameters. If you need to change the default parameters
350360
of `find_dotenv()`, you can explicitly call `find_dotenv()` and pass the result
351361
to this function as `dotenv_path`.
362+
363+
If the environment variable `PYTHON_DOTENV_DISABLED` is set to a truthy value,
364+
.env loading is disabled.
352365
"""
353366
if _load_dotenv_disabled():
354367
logger.debug(
355-
"python-dotenv: .env loading disabled by PYTHON_DOTENV_DISABLED environment variable"
356-
)
368+
"python-dotenv: .env loading disabled by PYTHON_DOTENV_DISABLED environment variable"
369+
)
357370
return False
358371

359372
if dotenv_path is None and stream is None:
@@ -404,12 +417,3 @@ def dotenv_values(
404417
override=True,
405418
encoding=encoding,
406419
).dict()
407-
408-
def _load_dotenv_disabled() -> bool:
409-
"""
410-
Determine if dotenv loading has been disabled.
411-
"""
412-
if "PYTHON_DOTENV_DISABLED" not in os.environ:
413-
return False
414-
value = os.environ["PYTHON_DOTENV_DISABLED"].casefold()
415-
return value in {"1", "true", "t", "yes", "y"}

0 commit comments

Comments
 (0)