Skip to content

Commit

Permalink
Refactor out is_env_truthy
Browse files Browse the repository at this point in the history
  • Loading branch information
micahjsmith committed Nov 2, 2022
1 parent 93ca107 commit 38813b9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
15 changes: 3 additions & 12 deletions pipenv/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +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
from pipenv.utils.shell import env_to_bool
from pipenv.utils.shell import env_to_bool, is_env_truthy
from pipenv.vendor.vistir.misc import _isatty

# HACK: avoid resolver.py uses the wrong byte code files.
Expand All @@ -18,14 +17,6 @@
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:
return False
return os.environ.get(name).lower() not in FALSE_VALUES


def get_from_env(arg, prefix="PIPENV", check_for_negation=True, default=None):
"""
Check the environment for a variable, returning its truthy or stringified value
Expand Down Expand Up @@ -86,7 +77,7 @@ def normalize_pipfile_path(p):
SESSION_IS_INTERACTIVE = _isatty(sys.stdout)

# TF_BUILD indicates to Azure pipelines it is a build step
PIPENV_IS_CI = _is_env_truthy("CI") or _is_env_truthy("TF_BUILD")
PIPENV_IS_CI = is_env_truthy("CI") or is_env_truthy("TF_BUILD")


NO_COLOR = False
Expand All @@ -101,7 +92,7 @@ def normalize_pipfile_path(p):
PIPENV_HIDE_EMOJIS = (
os.environ.get("PIPENV_HIDE_EMOJIS") is None
and (os.name == "nt" or PIPENV_IS_CI)
or _is_env_truthy("PIPENV_HIDE_EMOJIS")
or is_env_truthy("PIPENV_HIDE_EMOJIS")
)
"""Disable emojis in output.
Expand Down
5 changes: 5 additions & 0 deletions pipenv/utils/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,11 @@ def env_to_bool(val):
raise ValueError(f"Value is not a valid boolean-like: {val}")


def is_env_truthy(name):
"""An environment variable is truthy if it exists and isn't one of (0, false, no, off)"""
return env_to_bool(os.getenv(name))


def project_python(project, system=False):
if not system:
python = project._which("python")
Expand Down

0 comments on commit 38813b9

Please sign in to comment.