diff --git a/pipenv/core.py b/pipenv/core.py index f815e5de..28d5f9a8 100644 --- a/pipenv/core.py +++ b/pipenv/core.py @@ -1566,10 +1566,7 @@ def format_pip_output(out, r=None): def warn_in_virtualenv(): # Only warn if pipenv isn't already active. - pipenv_active = os.environ.get("PIPENV_ACTIVE") - if (environments.PIPENV_USE_SYSTEM or environments.PIPENV_VIRTUALENV) and not ( - pipenv_active or environments.is_quiet() - ): + if environments.is_in_virtualenv() and not environments.is_quiet(): click.echo( "{0}: Pipenv found itself running within a virtual environment, " "so it will automatically use that environment, instead of " diff --git a/pipenv/environment.py b/pipenv/environment.py index 8ac78dd8..5f32747c 100644 --- a/pipenv/environment.py +++ b/pipenv/environment.py @@ -30,7 +30,7 @@ class Environment(object): self._modules = {'pkg_resources': pkg_resources, 'pipenv': pipenv} self.base_working_set = base_working_set if base_working_set else BASE_WORKING_SET prefix = normalize_path(prefix) - self.is_venv = not prefix == normalize_path(sys.prefix) + self.is_venv = is_venv or prefix != normalize_path(sys.prefix) if not sources: sources = [] self.project = project diff --git a/pipenv/environments.py b/pipenv/environments.py index 066c296d..2d9bfaa8 100644 --- a/pipenv/environments.py +++ b/pipenv/environments.py @@ -276,6 +276,11 @@ def is_quiet(threshold=-1): return PIPENV_VERBOSITY <= threshold +def is_in_virtualenv(): + pipenv_active = os.environ.get("PIPENV_ACTIVE") + return (PIPENV_USE_SYSTEM or PIPENV_VIRTUALENV) and not pipenv_active + + PIPENV_SPINNER_FAIL_TEXT = fix_utf8(u"✘ {0}") if not PIPENV_HIDE_EMOJIS else ("{0}") PIPENV_SPINNER_OK_TEXT = fix_utf8(u"✔ {0}") if not PIPENV_HIDE_EMOJIS else ("{0}") diff --git a/pipenv/project.py b/pipenv/project.py index 590fafe5..fa7adb3e 100644 --- a/pipenv/project.py +++ b/pipenv/project.py @@ -47,6 +47,7 @@ from .environments import ( PIPENV_TEST_INDEX, PIPENV_PYTHON, PIPENV_DEFAULT_PYTHON_VERSION, + is_in_virtualenv ) @@ -345,8 +346,8 @@ class Project(object): @property def environment(self): if not self._environment: - prefix = self.get_location_for_virtualenv() - is_venv = prefix == sys.prefix + prefix = self.virtualenv_location + is_venv = is_in_virtualenv() sources = self.sources if self.sources else [DEFAULT_SOURCE,] self._environment = Environment( prefix=prefix, is_venv=is_venv, sources=sources, pipfile=self.parsed_pipfile,