From fde365140ccbcab4aaec299e7a56a337a03e7634 Mon Sep 17 00:00:00 2001 From: frostming Date: Fri, 8 Mar 2019 14:48:01 +0800 Subject: [PATCH 1/4] let windows user configure to have emojis --- pipenv/core.py | 2 +- pipenv/environments.py | 13 ++++++++----- pipenv/progress.py | 29 ++++++++++++----------------- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/pipenv/core.py b/pipenv/core.py index 7daff2be6e..b1f8c9fe4d 100644 --- a/pipenv/core.py +++ b/pipenv/core.py @@ -678,7 +678,7 @@ def batch_install(deps_list, procs, failed_deps_queue, from .vendor.requirementslib.models.utils import strip_extras_markers_from_requirement failed = (not retry) if not failed: - label = INSTALL_LABEL if os.name != "nt" else "" + label = INSTALL_LABEL if not PIPENV_HIDE_EMOJIS else "" else: label = INSTALL_LABEL2 diff --git a/pipenv/environments.py b/pipenv/environments.py index f451062160..24ea563190 100644 --- a/pipenv/environments.py +++ b/pipenv/environments.py @@ -70,13 +70,18 @@ emulator, e.g. Cmder, cannot be detected correctly. """ -PIPENV_HIDE_EMOJIS = bool(os.environ.get("PIPENV_HIDE_EMOJIS")) +PIPENV_HIDE_EMOJIS = os.environ.get("PIPENV_HIDE_EMOJIS") """Disable emojis in output. Default is to show emojis. This is automatically set on Windows. """ -if os.name == "nt" or PIPENV_IS_CI: +if (PIPENV_HIDE_EMOJIS is None and (os.name == "nt" or PIPENV_IS_CI)) or ( + PIPENV_HIDE_EMOJIS is not None + and PIPENV_HIDE_EMOJIS.lower() not in ('0', 'false', 'no') +): PIPENV_HIDE_EMOJIS = True +else: + PIPENV_HIDE_EMOJIS = False PIPENV_IGNORE_VIRTUALENVS = bool(os.environ.get("PIPENV_IGNORE_VIRTUALENVS")) """If set, Pipenv will always assign a virtual environment for this project. @@ -295,9 +300,7 @@ def is_in_virtualenv(): if not pipenv_active and not ignore_virtualenvs: virtual_env = os.environ.get("VIRTUAL_ENV") use_system = bool(virtual_env) - return (use_system or virtual_env) and not ( - pipenv_active or ignore_virtualenvs - ) + return (use_system or virtual_env) and not (pipenv_active or ignore_virtualenvs) PIPENV_SPINNER_FAIL_TEXT = fix_utf8(u"✘ {0}") if not PIPENV_HIDE_EMOJIS else ("{0}") diff --git a/pipenv/progress.py b/pipenv/progress.py index 1328e4d51e..8968150ca5 100644 --- a/pipenv/progress.py +++ b/pipenv/progress.py @@ -21,25 +21,20 @@ STREAM = sys.stderr MILL_TEMPLATE = "%s %s %i/%i\r" DOTS_CHAR = "." -if os.name != "nt": - if PIPENV_HIDE_EMOJIS: - if PIPENV_COLORBLIND: - BAR_FILLED_CHAR = "=" - BAR_EMPTY_CHAR = "-" - else: - BAR_FILLED_CHAR = str(crayons.green("=", bold=True)) - BAR_EMPTY_CHAR = str(crayons.black("-")) +if PIPENV_HIDE_EMOJIS: + if PIPENV_COLORBLIND: + BAR_FILLED_CHAR = "=" + BAR_EMPTY_CHAR = "-" else: - if PIPENV_COLORBLIND: - BAR_FILLED_CHAR = "▉" - BAR_EMPTY_CHAR = " " - else: - BAR_FILLED_CHAR = str(crayons.green("▉", bold=True)) - BAR_EMPTY_CHAR = str(crayons.black("▉")) - + BAR_FILLED_CHAR = str(crayons.green("=", bold=True)) + BAR_EMPTY_CHAR = str(crayons.black("-")) else: - BAR_FILLED_CHAR = "=" - BAR_EMPTY_CHAR = "-" + if PIPENV_COLORBLIND: + BAR_FILLED_CHAR = "▉" + BAR_EMPTY_CHAR = " " + else: + BAR_FILLED_CHAR = str(crayons.green("▉", bold=True)) + BAR_EMPTY_CHAR = str(crayons.black("▉")) if (sys.version_info[0] >= 3) and (os.name != "nt"): BAR_TEMPLATE = u" %s%s%s %i/%i — {0}\r".format(crayons.black("%s")) From d3146d72fa358bfe2f23fa8ddff445969f62d312 Mon Sep 17 00:00:00 2001 From: frostming Date: Fri, 8 Mar 2019 14:54:54 +0800 Subject: [PATCH 2/4] add news --- news/3595.feature.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 news/3595.feature.rst diff --git a/news/3595.feature.rst b/news/3595.feature.rst new file mode 100644 index 0000000000..249d11cf65 --- /dev/null +++ b/news/3595.feature.rst @@ -0,0 +1 @@ +Now Windows users can make emojis shown by setting ``PIPENV_HIDE_EMOJIS=0``. From c55c5112b3a5725511227b9c4ad8b4eb2b624f50 Mon Sep 17 00:00:00 2001 From: frostming Date: Mon, 11 Mar 2019 08:58:19 +0800 Subject: [PATCH 3/4] move the logic to a function --- pipenv/environments.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/pipenv/environments.py b/pipenv/environments.py index 24ea563190..1408c99c77 100644 --- a/pipenv/environments.py +++ b/pipenv/environments.py @@ -13,6 +13,15 @@ # I hope I can remove this one day. os.environ["PYTHONDONTWRITEBYTECODE"] = fs_str("1") + +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 ("0", "false", "no", "off") + + PIPENV_IS_CI = bool("CI" in os.environ or "TF_BUILD" in os.environ) # HACK: Prevent invalid shebangs with Homebrew-installed Python: @@ -70,18 +79,15 @@ emulator, e.g. Cmder, cannot be detected correctly. """ -PIPENV_HIDE_EMOJIS = os.environ.get("PIPENV_HIDE_EMOJIS") +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") +) """Disable emojis in output. Default is to show emojis. This is automatically set on Windows. """ -if (PIPENV_HIDE_EMOJIS is None and (os.name == "nt" or PIPENV_IS_CI)) or ( - PIPENV_HIDE_EMOJIS is not None - and PIPENV_HIDE_EMOJIS.lower() not in ('0', 'false', 'no') -): - PIPENV_HIDE_EMOJIS = True -else: - PIPENV_HIDE_EMOJIS = False PIPENV_IGNORE_VIRTUALENVS = bool(os.environ.get("PIPENV_IGNORE_VIRTUALENVS")) """If set, Pipenv will always assign a virtual environment for this project. From 32a170e76b4a2f15a6ab64d8ba5439aebab86aee Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Sun, 10 Mar 2019 22:38:49 -0400 Subject: [PATCH 4/4] Update news fragment --- news/3595.feature.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/news/3595.feature.rst b/news/3595.feature.rst index 249d11cf65..30b755b974 100644 --- a/news/3595.feature.rst +++ b/news/3595.feature.rst @@ -1 +1 @@ -Now Windows users can make emojis shown by setting ``PIPENV_HIDE_EMOJIS=0``. +Added the ability for Windows users to enable emojis by setting ``PIPENV_HIDE_EMOJIS=0``.