mirror of
https://github.com/kennethreitz/pipenv.git
synced 2026-06-05 22:50:18 +00:00
Add ability to suppress nested venv courtesy notice
Added an environment variable, PIPENV_SUPPRESS_NESTED_WARNING, to be used to suppress the courtesy notice from warn_in_virtualenv. Changed wording of the courtesy notice to mention suppression variable. Fixes #2527.
This commit is contained in:
+12
-3
@@ -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_SUPPRESS_NESTED_WARNING,
|
||||
)
|
||||
|
||||
# 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_SUPPRESS_NESTED_WARNING)
|
||||
):
|
||||
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_SUPPRESS_NESTED_WARNING=1", bold=True),
|
||||
),
|
||||
err=True,
|
||||
)
|
||||
|
||||
@@ -162,6 +162,14 @@ PIPENV_SHELL_FANCY = bool(os.environ.get("PIPENV_SHELL_FANCY"))
|
||||
Default is to use the compatibility shell if possible.
|
||||
"""
|
||||
|
||||
PIPENV_SUPPRESS_NESTED_WARNING = bool(os.environ.get(
|
||||
'PIPENV_SUPPRESS_NESTED_WARNING'))
|
||||
"""If set, suppress the courtesy notice regarding nested virtual environments.
|
||||
|
||||
Default is to show a courtesy notice when pipenv finds itself running inside
|
||||
another virtual environment.
|
||||
"""
|
||||
|
||||
PIPENV_TIMEOUT = int(os.environ.get("PIPENV_TIMEOUT", 120))
|
||||
"""Max number of seconds Pipenv will wait for virtualenv creation to complete.
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import io
|
||||
|
||||
import pytest
|
||||
import mock
|
||||
from contextlib import redirect_stderr
|
||||
|
||||
from pipenv.core import warn_in_virtualenv
|
||||
|
||||
|
||||
@mock.patch('pipenv.environments.PIPENV_VIRTUALENV', 'totallyrealenv')
|
||||
@mock.patch('pipenv.environments.PIPENV_SUPPRESS_NESTED_WARNING', '1')
|
||||
@pytest.mark.core
|
||||
def test_suppress_nested_venv_warning():
|
||||
f = io.StringIO()
|
||||
# Capture the stderr of warn_in_virtualenv to test for the presence of the
|
||||
# courtesy notice.
|
||||
with redirect_stderr(f):
|
||||
warn_in_virtualenv()
|
||||
output = f.getvalue()
|
||||
assert 'Courtesy Notice' not in output
|
||||
Reference in New Issue
Block a user