From 96fec11b2986a4de0dc8515f78a151698c0199c3 Mon Sep 17 00:00:00 2001 From: MarkKoz Date: Thu, 2 Aug 2018 21:56:41 -0700 Subject: [PATCH] Fix virtualenv creation failure when a .venv file exists --- news/2680.bugfix | 1 + pipenv/project.py | 2 +- tests/integration/test_dot_venv.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 news/2680.bugfix diff --git a/news/2680.bugfix b/news/2680.bugfix new file mode 100644 index 00000000..405fb1dd --- /dev/null +++ b/news/2680.bugfix @@ -0,0 +1 @@ +Fixed virtualenv creation failure when a .venv file is present in the project root. diff --git a/pipenv/project.py b/pipenv/project.py index c5f451e4..e32296e5 100644 --- a/pipenv/project.py +++ b/pipenv/project.py @@ -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 diff --git a/tests/integration/test_dot_venv.py b/tests/integration/test_dot_venv.py index e7b157f3..2063701b 100644 --- a/tests/integration/test_dot_venv.py +++ b/tests/integration/test_dot_venv.py @@ -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()