mirror of
https://github.com/kennethreitz/pipenv.git
synced 2026-06-05 22:50:18 +00:00
Make sure to consider existing .venv directory
Fix #1993. I made it more general than the issue, so the .venv directory is honoured in all situations.
This commit is contained in:
+5
-6
@@ -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)
|
||||
|
||||
+8
-4
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user