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

fix: when a resolution is failed show a helpful error #6338

Merged
merged 2 commits into from
Jan 19, 2025
Merged
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
32 changes: 9 additions & 23 deletions pipenv/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ def show(self, file=None):
if isinstance(self.extra, str):
self.extra = [self.extra]
for extra in self.extra:
extra = f"[pipenv.exceptions.{self.__class__.__name__}]: {extra}"
console.print(extra)
console.print(f"{self.message}")

Expand Down Expand Up @@ -310,29 +309,16 @@ def __init__(self, message):
class ResolutionFailure(PipenvException):
def __init__(self, message, no_version_found=False):
extra = (
"{}: Your dependencies could not be resolved. You likely have a "
"mismatch in your sub-dependencies.\n "
"You can use {} to bypass this mechanism, then run "
"{} to inspect the versions actually installed in the virtualenv.\n "
"Hint: try {} if it is a pre-release dependency."
"".format(
click.style("Warning", fg="red", bold=True),
click.style("$ pipenv run pip install <requirement_name>", fg="yellow"),
click.style("$ pipenv graph", fg="yellow"),
click.style("$ pipenv lock --pre", fg="yellow"),
),
"Your dependencies could not be resolved. You likely have a "
"mismatch in your sub-dependencies.\n"
"You can use [yellow]$ pipenv run pip install <requirement_name>[/yellow] to bypass this mechanism, then run "
"[yellow]$ pipenv graph[/yellow] to inspect the versions actually installed in the virtualenv.\n"
"Hint: try [yellow]$ pipenv lock --pre[/yellow] if it is a pre-release dependency."
)
if "no version found at all" in message:
no_version_found = True
message = click.style(f"{message}", fg="yellow")
if no_version_found:
message = "{}\n{}".format(
message,
click.style(
"Please check your version specifier and version number. "
"See PEP440 for more information.",
fg="cyan",
),
if "no version found at all" in str(message):
message += (
"[cyan]Please check your version specifier and version number. "
"See PEP440 for more information.[/cyan]"
)
PipenvException.__init__(self, message, extra=extra)

Expand Down
3 changes: 1 addition & 2 deletions pipenv/utils/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,10 +765,9 @@ def resolve(cmd, st, project):
out = c.stdout.read()
if returncode != 0:
st.console.print(environments.PIPENV_SPINNER_FAIL_TEXT.format("Locking Failed!"))
# err.print(out.strip())
if not is_verbose:
err.print(errors)
raise RuntimeError("Failed to lock Pipfile.lock!")
raise ResolutionFailure("Failed to lock Pipfile.lock!")
if is_verbose:
err.print(out.strip())
return subprocess.CompletedProcess(c.args, returncode, out, errors)
Expand Down
Loading