Skip to content

Commit

Permalink
Fix behavior of VENV_IN_PROJECT setting
Browse files Browse the repository at this point in the history
  • Loading branch information
micahjsmith committed Nov 2, 2022
1 parent cd15007 commit 93ca107
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
10 changes: 2 additions & 8 deletions pipenv/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/test_environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 93ca107

Please sign in to comment.