From cb49805eac6aa0efb612aeec1241e22515f5b692 Mon Sep 17 00:00:00 2001 From: Darren Kavanagh Date: Wed, 27 Nov 2024 16:53:31 -0800 Subject: [PATCH] feat: rename USE_EMOJI to PIPX_USE_EMOJI Rename environmental variable USE_EMOJI to PIPX_USE_EMOJI. Keeps support for USE_EMOJI. Fixes #1395. --- changelog.d/1395.feature.md | 1 + src/pipx/commands/environment.py | 4 ++-- src/pipx/emojis.py | 5 ++++- src/pipx/main.py | 2 +- tests/test_emojis.py | 8 ++++---- tests/test_environment.py | 2 +- 6 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 changelog.d/1395.feature.md diff --git a/changelog.d/1395.feature.md b/changelog.d/1395.feature.md new file mode 100644 index 0000000000..68add6b63a --- /dev/null +++ b/changelog.d/1395.feature.md @@ -0,0 +1 @@ +Rename environmental variable `USE_EMOJI` to `PIPX_USE_EMOJI`. diff --git a/src/pipx/commands/environment.py b/src/pipx/commands/environment.py index e82408104b..a830667130 100644 --- a/src/pipx/commands/environment.py +++ b/src/pipx/commands/environment.py @@ -16,7 +16,7 @@ "PIPX_SHARED_LIBS", "PIPX_DEFAULT_PYTHON", "PIPX_FETCH_MISSING_PYTHON", - "USE_EMOJI", + "PIPX_USE_EMOJI", "PIPX_HOME_ALLOW_SPACE", ] @@ -34,7 +34,7 @@ def environment(value: str) -> ExitCode: "PIPX_VENV_CACHEDIR": paths.ctx.venv_cache, "PIPX_STANDALONE_PYTHON_CACHEDIR": paths.ctx.standalone_python_cachedir, "PIPX_DEFAULT_PYTHON": DEFAULT_PYTHON, - "USE_EMOJI": str(EMOJI_SUPPORT).lower(), + "PIPX_USE_EMOJI": str(EMOJI_SUPPORT).lower(), "PIPX_HOME_ALLOW_SPACE": str(paths.ctx.allow_spaces_in_home_path).lower(), } if value is None: diff --git a/src/pipx/emojis.py b/src/pipx/emojis.py index 37221dbded..60bb5bba18 100644 --- a/src/pipx/emojis.py +++ b/src/pipx/emojis.py @@ -20,7 +20,10 @@ def use_emojis() -> bool: platform_emoji_support = True except UnicodeEncodeError: platform_emoji_support = False - return strtobool(str(os.getenv("USE_EMOJI", platform_emoji_support))) + use_emoji = os.getenv("PIPX_USE_EMOJI") + if use_emoji is None: + use_emoji = str(os.getenv("USE_EMOJI", platform_emoji_support)) + return strtobool(use_emoji) EMOJI_SUPPORT = use_emojis() diff --git a/src/pipx/main.py b/src/pipx/main.py index 4800f64313..ab19fb6a74 100644 --- a/src/pipx/main.py +++ b/src/pipx/main.py @@ -92,7 +92,7 @@ def prog_name() -> str: PIPX_MAN_DIR Overrides location of manual pages installations. Manual pages are symlinked or copied here. PIPX_GLOBAL_MAN_DIR Used instead of PIPX_MAN_DIR when the `--global` option is given. PIPX_DEFAULT_PYTHON Overrides default python used for commands. - USE_EMOJI Overrides emoji behavior. Default value varies based on platform. + PIPX_USE_EMOJI Overrides emoji behavior. Default value varies based on platform. PIPX_HOME_ALLOW_SPACE Overrides default warning on spaces in the home path """, subsequent_indent=" " * 24, # match the indent of argparse options diff --git a/tests/test_emojis.py b/tests/test_emojis.py index b93ce85e90..d1e9f9f20e 100644 --- a/tests/test_emojis.py +++ b/tests/test_emojis.py @@ -8,7 +8,7 @@ @pytest.mark.parametrize( - "USE_EMOJI, encoding, expected", + "PIPX_USE_EMOJI, encoding, expected", [ # utf-8 (None, "utf-8", True), @@ -39,8 +39,8 @@ ("false", "cp1252", False), ], ) -def test_use_emojis(monkeypatch, USE_EMOJI, encoding, expected): +def test_use_emojis(monkeypatch, PIPX_USE_EMOJI, encoding, expected): with mock.patch.object(sys, "stderr", TextIOWrapper(BytesIO(), encoding=encoding)): - if USE_EMOJI is not None: - monkeypatch.setenv("USE_EMOJI", USE_EMOJI) + if PIPX_USE_EMOJI is not None: + monkeypatch.setenv("PIPX_USE_EMOJI", PIPX_USE_EMOJI) assert use_emojis() is expected diff --git a/tests/test_environment.py b/tests/test_environment.py index e382154681..c252469469 100644 --- a/tests/test_environment.py +++ b/tests/test_environment.py @@ -33,7 +33,7 @@ def test_cli_with_args(monkeypatch, capsys): assert not run_pipx_cli(["environment", "--value", "PIPX_TRASH_DIR"]) assert not run_pipx_cli(["environment", "--value", "PIPX_VENV_CACHEDIR"]) assert not run_pipx_cli(["environment", "--value", "PIPX_DEFAULT_PYTHON"]) - assert not run_pipx_cli(["environment", "--value", "USE_EMOJI"]) + assert not run_pipx_cli(["environment", "--value", "PIPX_USE_EMOJI"]) assert not run_pipx_cli(["environment", "--value", "PIPX_HOME_ALLOW_SPACE"]) assert run_pipx_cli(["environment", "--value", "SSS"])