Skip to content

Commit

Permalink
Merge pull request #2645 from pypa/bugfix/2527-pipenv-verbosity
Browse files Browse the repository at this point in the history
PIPENV_VERBOSITY
  • Loading branch information
uranusjr authored Jul 25, 2018
2 parents 350aede + 68b1bce commit 9e2f829
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
2 changes: 2 additions & 0 deletions news/2527.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Added environment variable `PIPENV_VERBOSITY` to control output verbosity
without needing to pass options.
15 changes: 12 additions & 3 deletions pipenv/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1612,19 +1612,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,
)
Expand Down
7 changes: 7 additions & 0 deletions pipenv/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@
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.
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/test_core.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9e2f829

Please sign in to comment.