diff --git a/pipenv/core.py b/pipenv/core.py index a678a3b224..b4cd2eb5f8 100644 --- a/pipenv/core.py +++ b/pipenv/core.py @@ -1631,19 +1631,28 @@ def gen(out): def warn_in_virtualenv(): - from .environments import PIPENV_USE_SYSTEM, PIPENV_VIRTUALENV + from .environments import ( + PIPENV_USE_SYSTEM, + PIPENV_VIRTUALENV, + PIPENV_VERBOSITY, + ) # Only warn if pipenv isn't already active. pipenv_active = os.environ.get("PIPENV_ACTIVE") - if (PIPENV_USE_SYSTEM or PIPENV_VIRTUALENV) and not pipenv_active: + if ( + (PIPENV_USE_SYSTEM or PIPENV_VIRTUALENV) + and not (pipenv_active or PIPENV_VERBOSITY > 0) + ): click.echo( "{0}: Pipenv found itself running within a virtual environment, " "so it will automatically use that environment, instead of " "creating its own for any project. You can set " "{1} to force pipenv to ignore that environment and create " - "its own instead.".format( + "its own instead. You can set {2} to suppress this " + "warning.".format( crayons.green("Courtesy Notice"), crayons.normal("PIPENV_IGNORE_VIRTUALENVS=1", bold=True), + crayons.normal("PIPENV_VERBOSITY=1", bold=True), ), err=True, ) diff --git a/pipenv/environments.py b/pipenv/environments.py index f241172a14..32c5e1c525 100644 --- a/pipenv/environments.py +++ b/pipenv/environments.py @@ -174,6 +174,12 @@ Default is to create new virtual environments in a global location. """ +PIPENV_VERBOSITY = int(os.environ.get("PIPENV_VERBOSITY", "0")) +"""Verbosity setting for pipenv. Higher values make pipenv less verbose. + +Default is 0, for maximum verbosity. +""" + PIPENV_YES = bool(os.environ.get("PIPENV_YES")) """If set, Pipenv automatically assumes "yes" at all prompts. diff --git a/tests/unit/test_core.py b/tests/unit/test_core.py new file mode 100644 index 0000000000..7b19c085cb --- /dev/null +++ b/tests/unit/test_core.py @@ -0,0 +1,15 @@ +import pytest +import mock + +from pipenv.core import warn_in_virtualenv + + +@mock.patch('pipenv.environments.PIPENV_VIRTUALENV', 'totallyrealenv') +@mock.patch('pipenv.environments.PIPENV_VERBOSITY', 1) +@pytest.mark.core +def test_suppress_nested_venv_warning(capsys): + # Capture the stderr of warn_in_virtualenv to test for the presence of the + # courtesy notice. + warn_in_virtualenv() + output, err = capsys.readouterr() + assert 'Courtesy Notice' not in err