diff --git a/news/2527.feature b/news/2527.feature new file mode 100644 index 00000000..e8148a59 --- /dev/null +++ b/news/2527.feature @@ -0,0 +1,2 @@ +Added environment variable `PIPENV_VERBOSITY` to control output verbosity +without needing to pass options. diff --git a/pipenv/core.py b/pipenv/core.py index 4ecf5d4a..25bd0b7e 100644 --- a/pipenv/core.py +++ b/pipenv/core.py @@ -1612,19 +1612,28 @@ def format_pip_output(out, r=None): 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 f241172a..afe82988 100644 --- a/pipenv/environments.py +++ b/pipenv/environments.py @@ -174,6 +174,13 @@ PIPENV_VENV_IN_PROJECT = bool(os.environ.get("PIPENV_VENV_IN_PROJECT")) 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 more verbose, lower values less so. Default is 0, +for normal 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 00000000..e737a59e --- /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