mirror of
https://github.com/kennethreitz/pipenv.git
synced 2026-06-05 22:50:18 +00:00
Merge pull request #2699 from MarkKoz/bugfix/2680
Fix virtualenv creation failure when a .venv file exists
This commit is contained in:
@@ -0,0 +1 @@
|
||||
Fixed virtualenv creation failure when a .venv file is present in the project root.
|
||||
+1
-1
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user