diff --git a/pipenv/core.py b/pipenv/core.py index 9e761ff7..73932de6 100644 --- a/pipenv/core.py +++ b/pipenv/core.py @@ -53,7 +53,6 @@ from .environments import ( PIPENV_COLORBLIND, PIPENV_NOSPIN, PIPENV_SHELL_FANCY, - PIPENV_VENV_IN_PROJECT, PIPENV_TIMEOUT, PIPENV_SKIP_VALIDATION, PIPENV_HIDE_EMOJIS, @@ -878,7 +877,7 @@ def do_create_virtualenv(python=None, site_packages=False): err=True, ) # The user wants the virtualenv in the project. - if PIPENV_VENV_IN_PROJECT: + if project.is_venv_in_project(): cmd = [ 'virtualenv', project.virtualenv_location, @@ -928,7 +927,7 @@ def do_create_virtualenv(python=None, site_packages=False): sys.exit(1) click.echo(crayons.blue(c.out), err=True) # Enable site-packages, if desired... - if not PIPENV_VENV_IN_PROJECT and site_packages: + if not project.is_venv_in_project() and site_packages: click.echo( crayons.normal(u'Making site-packages available…', bold=True), err=True, @@ -2145,7 +2144,7 @@ def do_shell(three=None, python=False, fancy=False, shell_args=None): args = [] # Standard (properly configured shell) mode: else: - if PIPENV_VENV_IN_PROJECT: + if project.is_venv_in_project(): # use .venv as the target virtualenv name workon_name = '.venv' else: @@ -2157,7 +2156,7 @@ def do_shell(three=None, python=False, fancy=False, shell_args=None): terminal_dimensions = get_terminal_size() try: with temp_environ(): - if PIPENV_VENV_IN_PROJECT: + if project.is_venv_in_project(): os.environ['WORKON_HOME'] = project.project_directory c = pexpect.spawn( cmd, @@ -2171,7 +2170,7 @@ def do_shell(three=None, python=False, fancy=False, shell_args=None): # import subprocess # Tell pew to use the project directory as its workon_home with temp_environ(): - if PIPENV_VENV_IN_PROJECT: + if project.is_venv_in_project(): os.environ['WORKON_HOME'] = project.project_directory pew.workon_cmd([workon_name]) sys.exit(0) diff --git a/pipenv/project.py b/pipenv/project.py index 70e05006..a914c990 100644 --- a/pipenv/project.py +++ b/pipenv/project.py @@ -197,6 +197,12 @@ class Project(object): def requirements_exists(self): return bool(self.requirements_location) + def is_venv_in_project(self): + return ( + PIPENV_VENV_IN_PROJECT or + os.path.exists(os.path.join(self.project_directory, '.venv')) + ) + @property def virtualenv_exists(self): # TODO: Decouple project from existence of Pipfile. @@ -252,7 +258,7 @@ class Project(object): # This should work most of the time, for non-WIndows, in-project venv, # or "proper" path casing (on Windows). if (os.name != 'nt' or - PIPENV_VENV_IN_PROJECT or + self.is_venv_in_project() or self._get_virtualenv_location(venv_name)): return clean_name, encoded_hash @@ -287,11 +293,9 @@ class Project(object): # Use cached version, if available. if self._virtualenv_location: return self._virtualenv_location - venv_in_project = PIPENV_VENV_IN_PROJECT or \ - os.path.exists(os.path.join(self.project_directory, '.venv')) # Default mode. - if not venv_in_project: + if not self.is_venv_in_project(): loc = self._get_virtualenv_location(self.virtualenv_name) # The user wants the virtualenv in the project. else: