Ignore existing venv dir when PIPENV_VENV_IN_PROJECT is false (#6009)

This commit is contained in:
Arnaud Dezandee
2023-11-14 23:40:56 +01:00
committed by GitHub
parent cd961a41b8
commit bb0ca90fec
2 changed files with 25 additions and 6 deletions
+2 -6
View File
@@ -427,16 +427,12 @@ class Project:
dot_venv = os.path.join(self.project_directory, ".venv")
# If there's no .venv in project root, set location based on config.
if not os.path.exists(dot_venv):
# If there's no .venv in project root or it is a folder, set location based on config.
if not os.path.exists(dot_venv) or os.path.isdir(dot_venv):
if self.is_venv_in_project():
return dot_venv
return str(get_workon_home().joinpath(self.virtualenv_name))
# If .venv in project root is a directory, use it.
if os.path.isdir(dot_venv):
return dot_venv
# Now we assume .venv in project root is a file. Use its content.
with open(dot_venv) as f:
name = f.read().strip()
+23
View File
@@ -62,6 +62,29 @@ def test_venv_at_project_root(true_value, pipenv_instance_pypi):
assert normalize_drive(p.path) in p.pipenv('--venv').stdout
@pytest.mark.dotvenv
@pytest.mark.parametrize("false_value", FALSE_VALUES)
def test_venv_in_project_disabled_with_existing_venv_dir(false_value, pipenv_instance_pypi):
venv_name = "my_project"
with temp_environ(), pipenv_instance_pypi() as p, TemporaryDirectory(
prefix="pipenv-", suffix="temp_workon_home"
) as workon_home:
os.environ['PIPENV_VENV_IN_PROJECT'] = false_value
os.environ['PIPENV_CUSTOM_VENV_NAME'] = venv_name
os.environ["WORKON_HOME"] = workon_home
os.mkdir('.venv')
c = p.pipenv('install')
assert c.returncode == 0
c = p.pipenv('--venv')
assert c.returncode == 0
venv_loc = Path(c.stdout.strip()).absolute()
assert venv_loc.exists()
assert venv_loc.joinpath('.project').exists()
venv_path = normalize_drive(venv_loc.as_posix())
venv_expected_path = Path(workon_home).joinpath(venv_name).absolute().as_posix()
assert venv_path == normalize_drive(venv_expected_path)
@pytest.mark.dotvenv
def test_reuse_previous_venv(pipenv_instance_pypi):
with pipenv_instance_pypi() as p: