From 93ca10759918bc1c31756f198ed53c31dd7236d0 Mon Sep 17 00:00:00 2001 From: Micah Smith Date: Tue, 1 Nov 2022 21:15:58 -0400 Subject: [PATCH] Fix behavior of VENV_IN_PROJECT setting --- pipenv/environments.py | 10 ++-------- tests/unit/test_environments.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/pipenv/environments.py b/pipenv/environments.py index bc1d588861..e5e0cd9106 100644 --- a/pipenv/environments.py +++ b/pipenv/environments.py @@ -8,7 +8,7 @@ from pipenv._compat import fix_utf8 from pipenv.patched.pip._vendor.platformdirs import user_cache_dir -from pipenv.utils.constants import FALSE_VALUES, TRUE_VALUES +from pipenv.utils.constants import FALSE_VALUES from pipenv.utils.shell import env_to_bool from pipenv.vendor.vistir.misc import _isatty @@ -18,6 +18,7 @@ os.environ["PYTHONDONTWRITEBYTECODE"] = "1" +# TODO(micahjsmith) refactor to use env2bool def _is_env_truthy(name): """An environment variable is truthy if it exists and isn't one of (0, false, no, off)""" if name not in os.environ: @@ -279,13 +280,6 @@ def __init__(self) -> None: """ self.PIPENV_VENV_IN_PROJECT = get_from_env("VENV_IN_PROJECT") - if self.PIPENV_VENV_IN_PROJECT is not None: - if self.PIPENV_VENV_IN_PROJECT.lower() in TRUE_VALUES: - self.PIPENV_VENV_IN_PROJECT = True - elif self.PIPENV_VENV_IN_PROJECT.lower() in FALSE_VALUES: - self.PIPENV_VENV_IN_PROJECT = False - else: - self.PIPENV_VENV_IN_PROJECT = None """ When set True, will create or use the ``.venv`` in your project directory. When Set False, will ignore the .venv in your project directory even if it exists. If unset (default), will use the .venv of project directory should it exist, otherwise diff --git a/tests/unit/test_environments.py b/tests/unit/test_environments.py index eee669cc3e..b5bfbef4b5 100644 --- a/tests/unit/test_environments.py +++ b/tests/unit/test_environments.py @@ -86,3 +86,18 @@ def test_get_from_env_default(check_for_negation, default): ) == default ) + + +def test_pipenv_venv_in_project_set_true(monkeypatch): + monkeypatch.setenv("PIPENV_VENV_IN_PROJECT", "1") + assert environments.Setting().PIPENV_VENV_IN_PROJECT is True + + +def test_pipenv_venv_in_project_set_false(monkeypatch): + monkeypatch.setenv("PIPENV_VENV_IN_PROJECT", "0") + assert environments.Setting().PIPENV_VENV_IN_PROJECT is False + + +def test_pipenv_venv_in_project_unset(monkeypatch): + monkeypatch.delenv("PIPENV_VENV_IN_PROJECT", raising=False) + assert environments.Setting().PIPENV_VENV_IN_PROJECT is None