Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove click echo from utils #6352

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 14 additions & 26 deletions pipenv/utils/environment.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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."
)
9 changes: 3 additions & 6 deletions pipenv/utils/processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
34 changes: 10 additions & 24 deletions pipenv/utils/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()