Skip to content

Commit 24f3d61

Browse files
committed
refactor: remove all click from exceptions
Signed-off-by: Oz Tiram <oz.tiram@gmail.com>
1 parent 66c7715 commit 24f3d61

File tree

1 file changed

+18
-52
lines changed

1 file changed

+18
-52
lines changed

pipenv/exceptions.py

+18-52
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from pipenv.patched.pip._vendor.rich.panel import Panel
88
from pipenv.patched.pip._vendor.rich.text import Text
99
from pipenv.utils import err
10-
from pipenv.vendor import click
1110
from pipenv.vendor.click.exceptions import ClickException, FileError
1211

1312

@@ -77,29 +76,6 @@ def show(self):
7776
err.print(panel)
7877

7978

80-
class PipenvException(ClickException):
81-
message = "[bold][red]ERROR[/red][/bold]: {}"
82-
83-
def __init__(self, message=None, **kwargs):
84-
if not message:
85-
message = "Pipenv encountered a problem and had to exit."
86-
extra = kwargs.pop("extra", [])
87-
self.message = self.message.format(message)
88-
self.extra = extra
89-
90-
def show(self, file=None):
91-
if file is None:
92-
file = sys.stderr
93-
console = Console(file=file)
94-
if self.extra:
95-
if isinstance(self.extra, str):
96-
self.extra = [self.extra]
97-
for extra in self.extra:
98-
extra = f"[pipenv.exceptions.{self.__class__.__name__}]: {extra}"
99-
console.print(extra)
100-
console.print(f"{self.message}")
101-
102-
10379
class PipenvCmdError(OSError):
10480
def __init__(self, cmd, stdout, stderr, return_code):
10581
self.cmd = cmd
@@ -297,35 +273,31 @@ def __init__(self, msg):
297273

298274
class ResolutionFailure(RichException):
299275
def __init__(self, message, no_version_found=False):
276+
cmd = "[yellow]$ pipenv run pip install <requirement_name>[/yellow]"
277+
graph = "[yellow]$ pipenv graph[/yellow]"
278+
hint = "[yellow]$ pipenv lock --pre[/yellow]"
279+
300280
extra = (
301-
"{}: Your dependencies could not be resolved. You likely have a "
281+
f"[red bold]Warning[/red bold]: Your dependencies could not be resolved. You likely have a "
302282
"mismatch in your sub-dependencies.\n "
303-
"You can use {} to bypass this mechanism, then run "
304-
"{} to inspect the versions actually installed in the virtualenv.\n "
305-
"Hint: try {} if it is a pre-release dependency."
306-
"".format(
307-
click.style("Warning", fg="red", bold=True),
308-
click.style("$ pipenv run pip install <requirement_name>", fg="yellow"),
309-
click.style("$ pipenv graph", fg="yellow"),
310-
click.style("$ pipenv lock --pre", fg="yellow"),
311-
),
283+
f"You can use {cmd} to bypass this mechanism, then run "
284+
f"{graph} to inspect the versions actually installed in the virtualenv.\n "
285+
f"Hint: try {hint} if it is a pre-release dependency."
312286
)
313287
if "no version found at all" in message:
314288
no_version_found = True
315-
message = click.style(f"{message}", fg="yellow")
289+
message = f"[yellow]{message}[/yellow]"
316290
if no_version_found:
317-
message = "{}\n{}".format(
318-
message,
319-
click.style(
320-
"Please check your version specifier and version number. "
321-
"See PEP440 for more information.",
322-
fg="cyan",
323-
),
291+
message += (
292+
"\n[cyan]Please check your version specifier and version number. "
293+
"See PEP440 for more information.[/cyan]"
324294
)
325-
PipenvException.__init__(self, message, extra=extra)
295+
296+
message += extra
297+
super().__init__(self, message)
326298

327299

328-
class RequirementError(PipenvException):
300+
class RequirementError(RichException):
329301
def __init__(self, req=None):
330302
from pipenv.utils.constants import VCS_LIST
331303

@@ -358,14 +330,8 @@ def __init__(self, req=None):
358330
req_value = "\n".join([f" {k}: {v}" for k, v in values])
359331
else:
360332
req_value = getattr(req.line_instance, "line", None)
361-
message = click.style(
362-
f"Failed creating requirement instance {req_value}",
363-
bold=False,
364-
fg="reset",
365-
bg="reset",
366-
)
367-
extra = [str(req)]
368-
PipenvException.__init__(self, message, extra=extra)
333+
message = f"Failed creating requirement instance {req_value} {[str(req)]}"
334+
super().__init__(self, message)
369335

370336

371337
def prettify_exc(error):

0 commit comments

Comments
 (0)