From 38813b96b8a978356628fc33a6779ea7f653926c Mon Sep 17 00:00:00 2001 From: Micah Smith Date: Tue, 1 Nov 2022 21:57:12 -0400 Subject: [PATCH] Refactor out is_env_truthy --- pipenv/environments.py | 15 +++------------ pipenv/utils/shell.py | 5 +++++ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/pipenv/environments.py b/pipenv/environments.py index e5e0cd9106..5b9a1499d2 100644 --- a/pipenv/environments.py +++ b/pipenv/environments.py @@ -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. @@ -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 @@ -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 @@ -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. diff --git a/pipenv/utils/shell.py b/pipenv/utils/shell.py index a8765e2987..1668d7574c 100644 --- a/pipenv/utils/shell.py +++ b/pipenv/utils/shell.py @@ -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")