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

Fix #2527: Add ability to suppress nested venv courtesy notice #2581

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
15 changes: 12 additions & 3 deletions pipenv/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
6 changes: 6 additions & 0 deletions pipenv/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

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