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 all click.style calls from exceptions.py #6219

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions news/6216.vendor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove click.echo from exceptions.py
50 changes: 18 additions & 32 deletions pipenv/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ def show(self, file=None):


class PipenvFileError(FileError):
formatted_message = "{} {{}} {{}}".format(click.style("ERROR:", fg="red", bold=True))
formatted_message = "{} {{}} {{}}".format("[bold red]ERROR:[/bold red]")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure -- does this work or does it have to be [bold][red]?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it works like that, it can be either

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok thanks --sorry I accidentally marked this as ready for review -- feel free to change back.


def __init__(self, filename, message=None, **kwargs):
extra = kwargs.pop("extra", [])
if not message:
message = click.style("Please ensure that the file exists!", bold=True)
message = "[bold]Please ensure that the file exists![/bold]"
message = self.formatted_message.format(
click.style(f"{filename} not found!", bold=True), message
f"[bold]{filename} not found![/bold]", message
)
FileError.__init__(self, filename=filename, hint=message, **kwargs)
self.extra = extra
Expand All @@ -163,12 +163,8 @@ class PipfileNotFound(PipenvFileError):
def __init__(self, filename="Pipfile", extra=None, **kwargs):
extra = kwargs.pop("extra", [])
message = "{} {}".format(
click.style("Aborting!", bold=True, fg="red"),
click.style(
"Please ensure that the file exists and is located in your"
" project root directory.",
bold=True,
),
"[bold red]Aborting![/bold red]",
"[bold]Please ensure that the file exists and is located in your project root directory.[/bold]",
)
super().__init__(filename, message=message, extra=extra, **kwargs)

Expand All @@ -177,17 +173,17 @@ class LockfileNotFound(PipenvFileError):
def __init__(self, filename="Pipfile.lock", extra=None, **kwargs):
extra = kwargs.pop("extra", [])
message = "{} {} {}".format(
click.style("You need to run", bold=True),
click.style("$ pipenv lock", bold=True, fg="red"),
click.style("before you can continue.", bold=True),
"[bold]You need to run[/bold]",
"[bold red]$ pipenv lock[/bold red]",
"[bold]before you can continue.[/bold]",
)
super().__init__(filename, message=message, extra=extra, **kwargs)


class DeployException(PipenvUsageError):
def __init__(self, message=None, **kwargs):
if not message:
message = click.style("Aborting deploy", bold=True)
message = "[bold]Aborting deploy[/bold]"
extra = kwargs.pop("extra", [])
PipenvUsageError.__init__(self, message=message, extra=extra, **kwargs)

Expand All @@ -206,12 +202,12 @@ def __init__(self, option_name="system", message=None, ctx=None, **kwargs):
extra += [
"{}: --system is intended to be used for Pipfile installation, "
"not installation of specific packages. Aborting.".format(
click.style("Warning", bold=True, fg="red")
"[bold red]Warning[/bold /red]",
),
]
if message is None:
message = "{} --deploy flag".format(
click.style("See also: {}", fg="cyan"),
"[cyan]See also: {}[/cyan]",
)
super().__init__(option_name, message=message, ctx=ctx, extra=extra, **kwargs)

Expand Down Expand Up @@ -260,18 +256,18 @@ class UninstallError(PipenvException):
def __init__(self, package, command, return_values, return_code, **kwargs):
extra = [
"{} {}".format(
click.style("Attempted to run command: ", fg="cyan"),
click.style(f"$ {command!r}", bold=True, fg="yellow"),
"[cyan]Attempting to run command: [/cyan]",
f"[bold yellow]$ {command!r}[/bold yellow]",
)
]
extra.extend(
[click.style(line.strip(), fg="cyan") for line in return_values.splitlines()]
[f"[cyan]{line.strip()}[/cyan]" for line in return_values.splitlines()]
)
if isinstance(package, (tuple, list, set)):
package = " ".join(package)
message = "{!s} {!s}...".format(
click.style("Failed to uninstall package(s)", fg="reset"),
click.style(f"{package}!s", bold=True, fg="yellow"),
"Failed to uninstall package(s)",
f"[bold yellow]{package}!s[/bold yellow]",
)
self.exit_code = return_code
PipenvException.__init__(self, message=message, extra=extra)
Expand All @@ -283,26 +279,16 @@ def __init__(self, package, **kwargs):
package_message = ""
if package is not None:
package_message = "Couldn't install package: {}\n".format(
click.style(f"{package!s}", bold=True)
f"[bold]{package!s}[/bold]"
)
message = "{} {}".format(
f"{package_message}",
click.style("Package installation failed...", fg="yellow"),
"[yellow]Package installation failed...[/yellow]",
)
extra = kwargs.pop("extra", [])
PipenvException.__init__(self, message=message, extra=extra, **kwargs)


class CacheError(PipenvException):
def __init__(self, path, **kwargs):
message = "{} {}\n{}".format(
click.style("Corrupt cache file", fg="cyan"),
click.style(f"{path!s}", fg="reset", bg="reset"),
click.style('Consider trying "pipenv lock --clear" to clear the cache.'),
)
PipenvException.__init__(self, message=message)


class DependencyConflict(PipenvException):
def __init__(self, message):
extra = [
Expand Down
Loading