Merge pull request #2699 from MarkKoz/bugfix/2680

Fix virtualenv creation failure when a .venv file exists
This commit is contained in:
Tzu-ping Chung
2018-08-03 17:58:42 +08:00
committed by GitHub
3 changed files with 30 additions and 1 deletions
+1
View File
@@ -0,0 +1 @@
Fixed virtualenv creation failure when a .venv file is present in the project root.
+1 -1
View File
@@ -249,7 +249,7 @@ class Project(object):
def is_venv_in_project(self):
return PIPENV_VENV_IN_PROJECT or (
self.project_directory
and os.path.exists(os.path.join(self.project_directory, ".venv"))
and os.path.isdir(os.path.join(self.project_directory, ".venv"))
)
@property
+28
View File
@@ -1,5 +1,6 @@
import os
from pipenv._compat import TemporaryDirectory, Path
from pipenv.project import Project
from pipenv.utils import temp_environ, normalize_drive, get_windows_path
from pipenv.vendor import delegator
@@ -39,3 +40,30 @@ def test_reuse_previous_venv(PipenvInstance, pypi):
c = p.pipenv('install requests')
assert c.return_code == 0
assert normalize_drive(p.path) in p.pipenv('--venv').out
@pytest.mark.dotvenv
def test_venv_file_exists(PipenvInstance, pypi):
"""Tests virtualenv creation & package installation when a .venv file exists
at the project root.
"""
with PipenvInstance(pypi=pypi, chdir=True) as p:
file_path = os.path.join(p.path, '.venv')
with open(file_path, 'w') as f:
f.write('')
with temp_environ(), TemporaryDirectory(
prefix='pipenv-', suffix='temp_workon_home'
) as workon_home:
os.environ['WORKON_HOME'] = workon_home.name
if 'PIPENV_VENV_IN_PROJECT' in os.environ:
del os.environ['PIPENV_VENV_IN_PROJECT']
c = p.pipenv('install requests')
assert c.return_code == 0
venv_loc = None
for line in c.err.splitlines():
if line.startswith('Virtualenv location:'):
venv_loc = Path(line.split(':', 1)[-1].strip())
assert venv_loc is not None
assert venv_loc.joinpath('.project').exists()