Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppressing .env loading message when PIPENV_QUIET is set #3457

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/2358.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Suppress .env loading message when PIPENV_QUIET is set
9 changes: 5 additions & 4 deletions pipenv/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,11 @@ def load_dot_env():
)

if os.path.isfile(dotenv_file):
click.echo(
crayons.normal(fix_utf8("Loading .env environment variables…"), bold=True),
err=True,
)
if not environments.is_quiet():
click.echo(
crayons.normal(fix_utf8("Loading .env environment variables…"), bold=True),
err=True,
)
else:
if environments.PIPENV_DOTENV_LOCATION:
click.echo(
Expand Down
31 changes: 31 additions & 0 deletions tests/unit/test_core.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding=utf-8 -*-

import os

import mock
Expand Down Expand Up @@ -57,3 +59,32 @@ def test_load_dot_env_warns_if_file_doesnt_exist(capsys):
load_dot_env()
output, err = capsys.readouterr()
assert 'Warning' in err


@pytest.mark.core
def test_load_dot_env_quiet(capsys):
# Setting PIPENV_QUIET in environment will suppress the .env loading message
message = 'Loading .env environment variables'

with temp_environ(), TemporaryDirectory(prefix='pipenv-', suffix='') as tempdir:
dotenv_path = os.path.join(tempdir.name, 'test.env')
with open(dotenv_path, 'w'):
pass

with mock.patch('pipenv.environments.PIPENV_DOTENV_LOCATION', dotenv_path):
Copy link
Contributor

@frostming frostming Jan 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to set PIPENV_QUIET environment variable, rather than patching the function here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well I wanted to to this, but the PIPENV_QUIET variable is removed at import-time :

del PIPENV_VERBOSE

Do you think patching PIPENV_VERBOSITY variable is acceptable instead ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I meant this line :

del PIPENV_QUIET

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, setting PIPENV_VERBOSITY to -1 looks fine to me.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok thanks, changes done

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can squash in one commit if you prefer

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have preference on this. Either is ok for me

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I just pushed the squashed commit

load_dot_env()

output, err = capsys.readouterr()
assert message in err

with mock.patch('pipenv.environments.PIPENV_VERBOSITY', -1):
load_dot_env()

output, err = capsys.readouterr()
assert message not in err

with mock.patch('pipenv.environments.PIPENV_VERBOSITY', 1):
load_dot_env()

output, err = capsys.readouterr()
assert message in err