From 4b61b83b47bced406c0cb5f2fcd92902332b295b Mon Sep 17 00:00:00 2001 From: Hielke Walinga Date: Fri, 21 May 2021 17:45:52 +0200 Subject: [PATCH 1/4] Only install and import colorama on Windows. It has no effect on other platforms. --- setup.cfg | 2 +- src/pipx/colors.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/setup.cfg b/setup.cfg index 3950ce7e1c..a8febb2946 100644 --- a/setup.cfg +++ b/setup.cfg @@ -31,7 +31,7 @@ include_package_data = true zip_safe = true python_requires = >=3.6 install_requires = - colorama>=0.4.4 + colorama>=0.4.4;sys_platform=="win32" userpath>=1.5.0 argcomplete>=1.9.4, <2.0 packaging>=20.0 diff --git a/src/pipx/colors.py b/src/pipx/colors.py index fa511d00d7..a368de730b 100644 --- a/src/pipx/colors.py +++ b/src/pipx/colors.py @@ -1,11 +1,13 @@ import sys from typing import Callable -import colorama # type: ignore +from pipx.constants import WINDOWS PRINT_COLOR = sys.stdout.isatty() -if PRINT_COLOR: +if PRINT_COLOR and WINDOWS: + import colorama # type: ignore + colorama.init() From 071d6d434d757a1e39e2dd2e14f620cade1a4a0d Mon Sep 17 00:00:00 2001 From: Hielke Walinga Date: Fri, 21 May 2021 20:31:47 +0200 Subject: [PATCH 2/4] Add entry on changelog. --- docs/changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.md b/docs/changelog.md index a3707d5b11..294ba32ad0 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -2,6 +2,7 @@ dev - Fixed `pipx list --json` to return valid json with no venvs installed. Previously would return and empty string to stdout. (#681) - Changed `pipx ensurepath` bash behavior so that only one of {`~/.profile`, `~/.bash\_profile`} is modified with the extra pipx paths, not both. Previously, if a `.bash_profile` file was created where one didn't exist, it could cause problems, e.g. #456. The internal change is to use userpath v1.5.0 or greater. (#684) +* Colorama is now only installed on Windows. (#691) 0.16.2.1 From 9cdb7425afe21760c44b87870a4b39c2e85a24b5 Mon Sep 17 00:00:00 2001 From: Hielke Walinga Date: Sun, 23 May 2021 11:17:56 +0200 Subject: [PATCH 3/4] Use ImportError instead of platform check. --- src/pipx/colors.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/pipx/colors.py b/src/pipx/colors.py index a368de730b..a2db31f36f 100644 --- a/src/pipx/colors.py +++ b/src/pipx/colors.py @@ -1,13 +1,14 @@ import sys from typing import Callable -from pipx.constants import WINDOWS - PRINT_COLOR = sys.stdout.isatty() -if PRINT_COLOR and WINDOWS: +try: import colorama # type: ignore +except ImportError: # Colorama is Windows only package + colorama = None +if PRINT_COLOR and colorama: colorama.init() From 44af790b33791c5d5cacb3a8d197e024dcf844e5 Mon Sep 17 00:00:00 2001 From: Hielke Walinga Date: Sun, 23 May 2021 21:40:38 +0200 Subject: [PATCH 4/4] Move imports up. --- src/pipx/colors.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pipx/colors.py b/src/pipx/colors.py index a2db31f36f..4408878725 100644 --- a/src/pipx/colors.py +++ b/src/pipx/colors.py @@ -1,13 +1,13 @@ import sys from typing import Callable -PRINT_COLOR = sys.stdout.isatty() - try: import colorama # type: ignore except ImportError: # Colorama is Windows only package colorama = None +PRINT_COLOR = sys.stdout.isatty() + if PRINT_COLOR and colorama: colorama.init()