|
7 | 7 | from pipenv.patched.pip._vendor.rich.panel import Panel
|
8 | 8 | from pipenv.patched.pip._vendor.rich.text import Text
|
9 | 9 | from pipenv.utils import err
|
10 |
| -from pipenv.vendor import click |
11 | 10 | from pipenv.vendor.click.exceptions import ClickException, FileError
|
12 | 11 |
|
13 | 12 |
|
@@ -77,29 +76,6 @@ def show(self):
|
77 | 76 | err.print(panel)
|
78 | 77 |
|
79 | 78 |
|
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 |
| - |
103 | 79 | class PipenvCmdError(OSError):
|
104 | 80 | def __init__(self, cmd, stdout, stderr, return_code):
|
105 | 81 | self.cmd = cmd
|
@@ -297,35 +273,31 @@ def __init__(self, msg):
|
297 | 273 |
|
298 | 274 | class ResolutionFailure(RichException):
|
299 | 275 | 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 | + |
300 | 280 | 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 " |
302 | 282 | "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." |
312 | 286 | )
|
313 | 287 | if "no version found at all" in message:
|
314 | 288 | no_version_found = True
|
315 |
| - message = click.style(f"{message}", fg="yellow") |
| 289 | + message = f"[yellow]{message}[/yellow]" |
316 | 290 | 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]" |
324 | 294 | )
|
325 |
| - PipenvException.__init__(self, message, extra=extra) |
| 295 | + |
| 296 | + message += extra |
| 297 | + super().__init__(self, message) |
326 | 298 |
|
327 | 299 |
|
328 |
| -class RequirementError(PipenvException): |
| 300 | +class RequirementError(RichException): |
329 | 301 | def __init__(self, req=None):
|
330 | 302 | from pipenv.utils.constants import VCS_LIST
|
331 | 303 |
|
@@ -358,14 +330,8 @@ def __init__(self, req=None):
|
358 | 330 | req_value = "\n".join([f" {k}: {v}" for k, v in values])
|
359 | 331 | else:
|
360 | 332 | 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) |
369 | 335 |
|
370 | 336 |
|
371 | 337 | def prettify_exc(error):
|
|
0 commit comments