Merge pull request #2645 from pypa/bugfix/2527-pipenv-verbosity

PIPENV_VERBOSITY
This commit is contained in:
Tzu-ping Chung
2018-07-25 15:46:27 +08:00
committed by GitHub
4 changed files with 36 additions and 3 deletions
+2
View File
@@ -0,0 +1,2 @@
Added environment variable `PIPENV_VERBOSITY` to control output verbosity
without needing to pass options.
+12 -3
View File
@@ -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,
)
+7
View File
@@ -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.
+15
View File
@@ -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