Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit07a4404

Browse files
authored
Fix: Suppress duplicate .env loading message in nested pipenv invocations (#6481)
When PIPENV_ACTIVE is set (indicating we're inside a pipenv environment),suppress the 'Loading .env environment variables...' message on subsequentpipenv commands. The .env file is still loaded, but the message is notprinted again to avoid duplicate output.This fixes the issue where running 'pipenv run script' where the scriptitself calls additional pipenv commands would print the .env loadingmessage multiple times.Fixes#6328
1 parentba81393 commit07a4404

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

‎pipenv/utils/environment.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ def load_dot_env(project, as_dict=False, quiet=False):
2929
ifas_dict:
3030
returndotenv.dotenv_values(str(dotenv_file))
3131
elifdotenv_file.is_file():
32-
ifnotquietandnotproject.s.is_quiet():
32+
# Skip message if already in a pipenv environment (nested invocation)
33+
if (
34+
notquiet
35+
andnotproject.s.is_quiet()
36+
andnotos.environ.get("PIPENV_ACTIVE")
37+
):
3338
err.print("[bold]Loading .env environment variables...[/bold]")
3439

3540
dotenv.load_dotenv(str(dotenv_file),override=True)

‎tests/unit/test_core.py‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ def test_load_dot_env_shows_message_without_quiet(monkeypatch, capsys, project):
127127
project.s.PIPENV_DOTENV_LOCATION=str(dotenv_path)
128128
# Ensure verbosity is at default (0)
129129
project.s.PIPENV_VERBOSITY=0
130+
# Ensure PIPENV_ACTIVE is not set
131+
os.environ.pop("PIPENV_ACTIVE",None)
130132
load_dot_env(project)
131133
output,err=capsys.readouterr()
132134
# The .env file should be loaded
@@ -135,6 +137,42 @@ def test_load_dot_env_shows_message_without_quiet(monkeypatch, capsys, project):
135137
assert"Loading .env"inerr
136138

137139

140+
@pytest.mark.core
141+
deftest_load_dot_env_suppresses_message_when_pipenv_active(monkeypatch,capsys,project):
142+
"""Test that the .env loading message is suppressed when PIPENV_ACTIVE is set.
143+
144+
This handles nested pipenv invocations (e.g., `pipenv run` executing a script
145+
that itself runs pipenv commands). The .env should still be loaded, but the
146+
message should not be printed again.
147+
148+
Fixes #6328
149+
"""
150+
withtemp_environ(),monkeypatch.context()asm,TemporaryDirectory(
151+
prefix="pipenv-",suffix=""
152+
)astempdir:
153+
ifos.name=="nt":
154+
frompipenv.vendorimportclick
155+
156+
is_console=False
157+
m.setattr(click._winconsole,"_is_console",lambdax:is_console)
158+
dotenv_path=os.path.join(tempdir,"test.env")
159+
key,val="NESTED_KEY","nested_value"
160+
withopen(dotenv_path,"w")asf:
161+
f.write(f"{key}={val}")
162+
163+
project.s.PIPENV_DOTENV_LOCATION=str(dotenv_path)
164+
# Ensure verbosity is at default (0) - message would normally show
165+
project.s.PIPENV_VERBOSITY=0
166+
# Set PIPENV_ACTIVE to simulate nested pipenv invocation
167+
os.environ["PIPENV_ACTIVE"]="1"
168+
load_dot_env(project)
169+
output,err=capsys.readouterr()
170+
# The .env file should still be loaded
171+
assertos.environ[key]==val
172+
# But the "Loading .env" message should be suppressed
173+
assert"Loading .env"notinerr
174+
175+
138176
@pytest.mark.core
139177
deftest_deactivate_wrapper_script_includes_unset_pipenv_active():
140178
"""Test that deactivate wrapper scripts include 'unset PIPENV_ACTIVE' or equivalent."""

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp