From ecd677f77955ca02e9bab1d1579faeb89fcd9103 Mon Sep 17 00:00:00 2001 From: Oz Tiram Date: Mon, 9 Dec 2024 22:41:05 +0100 Subject: [PATCH 1/8] chore: remove click.echo from pipenv/utils/project.py Signed-off-by: Oz Tiram --- pipenv/utils/project.py | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/pipenv/utils/project.py b/pipenv/utils/project.py index b6e58119f..9bec20a98 100644 --- a/pipenv/utils/project.py +++ b/pipenv/utils/project.py @@ -5,11 +5,11 @@ from pipenv import exceptions from pipenv.patched.pip._vendor.packaging.version import parse as parse_version from pipenv.patched.pip._vendor.typing_extensions import TYPE_CHECKING +from pipenv.utils import err from pipenv.utils.dependencies import python_version from pipenv.utils.pipfile import ensure_pipfile from pipenv.utils.shell import shorten_path from pipenv.utils.virtualenv import ensure_virtualenv -from pipenv.vendor import click if TYPE_CHECKING: from pipenv.patched.pip._vendor.typing_extensions import STRING_TYPE @@ -57,32 +57,18 @@ def ensure_project( if path_to_python and project.required_python_version not in ( python_version(path_to_python) or "" ): - click.echo( - "{}: Your Pipfile requires {} {}, " - "but you are using {} ({}).".format( - click.style("Warning", fg="red", bold=True), - click.style("python_version", bold=True), - click.style(project.required_python_version, fg="cyan"), - click.style( - python_version(path_to_python) or "unknown", fg="cyan" - ), - click.style(shorten_path(path_to_python), fg="green"), - ), - err=True, + err.print( + f"[red][bold]Warning[/bold][/red]: Your Pipfile requires" + f"[bold]{python_version}[/bold] [cyan]{python.required_python_version}[/cyan]," + f"but you are using [cyan]{python_version(path_to_python)}[/cyan]" + f"from [green]{shorten_path(path_to_python)}[/green]." ) - click.echo( - " {} and rebuilding the virtual environment " - "may resolve the issue.".format( - click.style("$ pipenv --rm", fg="green") - ), - err=True, + err.print( + "[green]$ pipenv --rm[/green] and rebuilding the virtual environment " + "may resolve the issue." ) if not deploy: - click.echo( - " {} will surely fail." - "".format(click.style("$ pipenv check", fg="yellow")), - err=True, - ) + err.print("[yellow]$ pipenv check[/yellow] will surely fail.") else: raise exceptions.DeployException # Ensure the Pipfile exists. From 985732f314dde0a6f14f601621b904d28281d2c7 Mon Sep 17 00:00:00 2001 From: Oz Tiram Date: Mon, 9 Dec 2024 22:56:59 +0100 Subject: [PATCH 2/8] chore: remove click from pipenv/utils/processes.py Signed-off-by: Oz Tiram --- pipenv/utils/processes.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/pipenv/utils/processes.py b/pipenv/utils/processes.py index 9c0ea8376..aaf7326e1 100644 --- a/pipenv/utils/processes.py +++ b/pipenv/utils/processes.py @@ -2,8 +2,8 @@ import subprocess from pipenv.exceptions import PipenvCmdError +from pipenv.utils import console, err from pipenv.utils.constants import MYPY_RUNNING -from pipenv.vendor import click if MYPY_RUNNING: from typing import Tuple # noqa @@ -33,13 +33,10 @@ def run_command(cmd, *args, is_verbose=False, **kwargs): kwargs["env"]["PYTHONIOENCODING"] = "UTF-8" command = [cmd.command, *cmd.args] if is_verbose: - click.echo(f"Running command: $ {cmd.cmdify()}") + console.print(f"Running command: $ {cmd.cmdify()}") c = subprocess_run(command, *args, **kwargs) if is_verbose: - click.echo( - "Command output: {}".format(click.style(c.stdout, fg="cyan")), - err=True, - ) + err.print(f"[cyan]Command output: {c.stdout}[/cyan]") if c.returncode and catch_exceptions: raise PipenvCmdError(cmd.cmdify(), c.stdout, c.stderr, c.returncode) return c From 3ce259bf180b73183d35ab3989266fa2a61046be Mon Sep 17 00:00:00 2001 From: Oz Tiram Date: Tue, 10 Dec 2024 22:13:21 +0100 Subject: [PATCH 3/8] chore: remove click.echo from pipenv/utils/environment.py Signed-off-by: Oz Tiram --- pipenv/utils/environment.py | 40 +++++++++++++------------------------ 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/pipenv/utils/environment.py b/pipenv/utils/environment.py index 89bba8eab..4b3e8a85a 100644 --- a/pipenv/utils/environment.py +++ b/pipenv/utils/environment.py @@ -1,7 +1,8 @@ import os from pipenv import environments -from pipenv.vendor import click, dotenv +from pipenv.utils import err +from pipenv.vendor import dotenv def load_dot_env(project, as_dict=False, quiet=False): @@ -14,41 +15,28 @@ def load_dot_env(project, as_dict=False, quiet=False): ) if not os.path.isfile(dotenv_file) and project.s.PIPENV_DOTENV_LOCATION: - click.echo( - "{}: file {}={} does not exist!!\n{}".format( - click.style("Warning", fg="red", bold=True), - click.style("PIPENV_DOTENV_LOCATION", bold=True), - click.style(project.s.PIPENV_DOTENV_LOCATION, bold=True), - click.style( - "Not loading environment variables.", fg="red", bold=True - ), - ), - err=True, + err.print( + f"[bold][red]WARNING[/red]:" + f"file PIPENV_DOTENV_LOCATION={project.s.PIPENV_DOTENV_LOCATION}" + "does not exist!" + "[red]Not loading environment variables.[/red][/bold]" ) if as_dict: return dotenv.dotenv_values(dotenv_file) elif os.path.isfile(dotenv_file): if not quiet: - click.secho( - "Loading .env environment variables...", - bold=True, - err=True, - ) - dotenv.load_dotenv(dotenv_file, override=True) + err.print("[bold]Loading .env environment variables...[/bold]") + dotenv.load_dotenv(dotenv_file, override=True) project.s = environments.Setting() def ensure_environment(): # Skip this on Windows... if os.name != "nt" and "LANG" not in os.environ: - click.echo( - "{}: the environment variable {} is not set!" - "\nWe recommend setting this in {} (or equivalent) for " - "proper expected behavior.".format( - click.style("Warning", fg="red", bold=True), - click.style("LANG", bold=True), - click.style("~/.profile", fg="green"), - ), - err=True, + err.print( + "[red]Warning[/red]: the environment variable [bold]LANG[/bold]" + "is not set!\nWe recommend setting this in" + "[green]~/.profile[/green] (or equivalent) for " + "proper expected behavior." ) From 96b33fe405aba42ff1320e59f2235bd1a6e8999a Mon Sep 17 00:00:00 2001 From: Oz Tiram Date: Thu, 6 Mar 2025 13:15:06 +0100 Subject: [PATCH 4/8] fix: failing test because of rich vs click API Signed-off-by: Oz Tiram --- tests/unit/test_core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test_core.py b/tests/unit/test_core.py index f96c6b976..bf96c2935 100644 --- a/tests/unit/test_core.py +++ b/tests/unit/test_core.py @@ -77,4 +77,4 @@ def test_load_dot_env_warns_if_file_doesnt_exist(monkeypatch, capsys, project): project.s.PIPENV_DOTENV_LOCATION = str(dotenv_path) load_dot_env(project) output, err = capsys.readouterr() - assert "Warning" in err + assert "WARNING" in err.upper() From 6f8d34b3a3ca059eefd0a2ca2010ad4340742162 Mon Sep 17 00:00:00 2001 From: Oz Tiram Date: Mon, 10 Mar 2025 09:14:41 +0100 Subject: [PATCH 5/8] fix: correct variable name in project.py Signed-off-by: Oz Tiram --- pipenv/utils/project.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipenv/utils/project.py b/pipenv/utils/project.py index 9bec20a98..db09e3974 100644 --- a/pipenv/utils/project.py +++ b/pipenv/utils/project.py @@ -59,7 +59,7 @@ def ensure_project( ): err.print( f"[red][bold]Warning[/bold][/red]: Your Pipfile requires" - f"[bold]{python_version}[/bold] [cyan]{python.required_python_version}[/cyan]," + f"[bold]{python_version}[/bold] [cyan]{project.required_python_version}[/cyan]," f"but you are using [cyan]{python_version(path_to_python)}[/cyan]" f"from [green]{shorten_path(path_to_python)}[/green]." ) From b66ecd30cb2060c78befb8d591b7c63a44670ee8 Mon Sep 17 00:00:00 2001 From: Oz Tiram Date: Mon, 10 Mar 2025 09:15:43 +0100 Subject: [PATCH 6/8] fix: formatting of error message in project.py Signed-off-by: Oz Tiram --- pipenv/utils/project.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pipenv/utils/project.py b/pipenv/utils/project.py index db09e3974..8c49bce20 100644 --- a/pipenv/utils/project.py +++ b/pipenv/utils/project.py @@ -58,9 +58,9 @@ def ensure_project( python_version(path_to_python) or "" ): err.print( - f"[red][bold]Warning[/bold][/red]: Your Pipfile requires" - f"[bold]{python_version}[/bold] [cyan]{project.required_python_version}[/cyan]," - f"but you are using [cyan]{python_version(path_to_python)}[/cyan]" + f"[red][bold]Warning[/bold][/red]: Your Pipfile requires " + f"[bold]{python_version}[/bold] [cyan]{project.required_python_version}[/cyan], " + f"but you are using [cyan]{python_version(path_to_python)}[/cyan] " f"from [green]{shorten_path(path_to_python)}[/green]." ) err.print( From 228129f6e127b5e0387eea909ae22c31ec92415a Mon Sep 17 00:00:00 2001 From: Oz Tiram Date: Mon, 10 Mar 2025 09:18:27 +0100 Subject: [PATCH 7/8] fix: formatting with spaces in environment.py Signed-off-by: Oz Tiram --- pipenv/utils/environment.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pipenv/utils/environment.py b/pipenv/utils/environment.py index 4b3e8a85a..051bc602f 100644 --- a/pipenv/utils/environment.py +++ b/pipenv/utils/environment.py @@ -35,8 +35,8 @@ def ensure_environment(): # Skip this on Windows... if os.name != "nt" and "LANG" not in os.environ: err.print( - "[red]Warning[/red]: the environment variable [bold]LANG[/bold]" - "is not set!\nWe recommend setting this in" + "[red]Warning[/red]: the environment variable [bold]LANG[/bold] " + "is not set!\nWe recommend setting this in " "[green]~/.profile[/green] (or equivalent) for " "proper expected behavior." ) From ffbe755169bae36aa35b3a99ac5a09482baad22f Mon Sep 17 00:00:00 2001 From: Oz Tiram Date: Mon, 10 Mar 2025 09:22:31 +0100 Subject: [PATCH 8/8] fix: correct error message specifying python version required Signed-off-by: Oz Tiram --- pipenv/utils/project.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipenv/utils/project.py b/pipenv/utils/project.py index 8c49bce20..5e6387bf2 100644 --- a/pipenv/utils/project.py +++ b/pipenv/utils/project.py @@ -59,7 +59,7 @@ def ensure_project( ): err.print( f"[red][bold]Warning[/bold][/red]: Your Pipfile requires " - f"[bold]{python_version}[/bold] [cyan]{project.required_python_version}[/cyan], " + f'[bold]"python_version"[/bold] [cyan]{project.required_python_version}[/cyan], ' f"but you are using [cyan]{python_version(path_to_python)}[/cyan] " f"from [green]{shorten_path(path_to_python)}[/green]." )