mirror of
https://github.com/kennethreitz/pipenv.git
synced 2026-06-05 14:50:16 +00:00
Merge pull request #4417 from pypa/bugfix/4412
only show courtesy notice when venv is activated
This commit is contained in:
@@ -0,0 +1 @@
|
||||
Correctly detect whether Pipenv in run under an activated virtualenv.
|
||||
+10
-17
@@ -367,16 +367,16 @@ def is_quiet(threshold=-1):
|
||||
return PIPENV_VERBOSITY <= threshold
|
||||
|
||||
|
||||
def _is_using_venv():
|
||||
def is_using_venv():
|
||||
# type: () -> bool
|
||||
"""Check for venv-based virtual environment which sets sys.base_prefix"""
|
||||
return sys.prefix != getattr(sys, "base_prefix", sys.prefix)
|
||||
|
||||
|
||||
def _is_using_virtualenv():
|
||||
# type: () -> bool
|
||||
"""Check for virtualenv-based environment which sets sys.real_prefix"""
|
||||
return getattr(sys, "real_prefix", None) is not None
|
||||
if getattr(sys, 'real_prefix', None) is not None:
|
||||
# virtualenv venvs
|
||||
result = True
|
||||
else:
|
||||
# PEP 405 venvs
|
||||
result = sys.prefix != getattr(sys, 'base_prefix', sys.prefix)
|
||||
return result
|
||||
|
||||
|
||||
def is_in_virtualenv():
|
||||
@@ -388,16 +388,9 @@ def is_in_virtualenv():
|
||||
"""
|
||||
|
||||
pipenv_active = os.environ.get("PIPENV_ACTIVE", False)
|
||||
virtual_env = None
|
||||
use_system = False
|
||||
virtual_env = bool(os.environ.get("VIRTUAL_ENV"))
|
||||
ignore_virtualenvs = bool(os.environ.get("PIPENV_IGNORE_VIRTUALENVS", False))
|
||||
|
||||
if not pipenv_active and not ignore_virtualenvs:
|
||||
virtual_env = any([
|
||||
_is_using_virtualenv(), _is_using_venv(), os.environ.get("VIRTUAL_ENV")
|
||||
])
|
||||
use_system = bool(virtual_env)
|
||||
return (use_system or virtual_env) and not (pipenv_active or ignore_virtualenvs)
|
||||
return virtual_env and not (pipenv_active or ignore_virtualenvs)
|
||||
|
||||
|
||||
PIPENV_SPINNER_FAIL_TEXT = fix_utf8(u"✘ {0}") if not PIPENV_HIDE_EMOJIS else ("{0}")
|
||||
|
||||
+2
-2
@@ -25,7 +25,7 @@ from .environment import Environment
|
||||
from .environments import (
|
||||
PIPENV_DEFAULT_PYTHON_VERSION, PIPENV_IGNORE_VIRTUALENVS, PIPENV_MAX_DEPTH,
|
||||
PIPENV_PIPFILE, PIPENV_PYTHON, PIPENV_TEST_INDEX, PIPENV_VENV_IN_PROJECT,
|
||||
PIPENV_USE_SYSTEM, is_in_virtualenv, is_type_checking
|
||||
PIPENV_USE_SYSTEM, is_in_virtualenv, is_type_checking, is_using_venv
|
||||
)
|
||||
from .vendor.requirementslib.models.utils import get_default_pyproject_backend
|
||||
from .utils import (
|
||||
@@ -349,7 +349,7 @@ class Project(object):
|
||||
|
||||
def get_environment(self, allow_global=False):
|
||||
# type: (bool) -> Environment
|
||||
is_venv = is_in_virtualenv()
|
||||
is_venv = is_in_virtualenv() or is_using_venv()
|
||||
if allow_global and not is_venv:
|
||||
prefix = sys.prefix
|
||||
python = sys.executable
|
||||
|
||||
Reference in New Issue
Block a user