Skip to content

Commit

Permalink
refactor: replace click exception with rich based
Browse files Browse the repository at this point in the history
Signed-off-by: Oz Tiram <[email protected]>
  • Loading branch information
oz123 committed Jan 9, 2025
1 parent 8d36feb commit 8bacc42
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions pipenv/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from traceback import format_tb

from pipenv.patched.pip._vendor.rich.console import Console
from pipenv.patched.pip._vendor.rich.panel import Panel
from pipenv.patched.pip._vendor.rich.text import Text
from pipenv.utils import err
from pipenv.vendor import click
Expand Down Expand Up @@ -61,6 +62,21 @@ def handle_exception(exc_type, exception, traceback, hook=sys.excepthook):
sys.excepthook = handle_exception


class RichException(Exception):
def __init__(self, message):
self.message = message

def show(self):
panel = Panel(
self.message,
title="Error",
expand=False,
border_style="red",
style="bold red",
)
err.print(panel)


class PipenvException(ClickException):
message = "[bold][red]ERROR[/red][/bold]: {}"

Expand Down Expand Up @@ -290,18 +306,13 @@ def __init__(self, package, **kwargs):
PipenvException.__init__(self, message=message, extra=extra, **kwargs)


class DependencyConflict(PipenvException):
def __init__(self, message):
extra = [
"{} {}".format(
click.style("The operation failed...", bold=True, fg="red"),
click.style(
"A dependency conflict was detected and could not be resolved.",
fg="red",
),
)
]
PipenvException.__init__(self, message, extra=extra)
class DependencyConflict(RichException):
def __init__(self, msg):
banner = (
"[red bold]The operation failed...[/bold][/red]\n"
"A dependency conflict for was detected and could not be resolved."
)
super().__init__(f"{banner}\n{msg}")


class ResolutionFailure(PipenvException):
Expand Down

0 comments on commit 8bacc42

Please sign in to comment.