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

Handle venv_resolve_deps exception #6166

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions news/6166.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This is an enhancement of error message regards to https://github.com/pypa/pipenv/issues/6073.
Inside ``do_lock`` method, exceptions in ``venv_resolve_deps`` wasn't properly handled by far. This PR handles exception to improve this problem.
Since RuntimeError raised inside ``venv_resolve_deps`` can't be easily modified, (it's related to so many components) it raises sys.exit(1) when RuntimeError occurs, and additional traceback log is added on general Exception.
43 changes: 28 additions & 15 deletions pipenv/routines/lock.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import contextlib
import sys
import traceback

from pipenv.patched.pip._vendor import rich
from pipenv.utils.dependencies import (
get_pipfile_category_using_lockfile_section,
)
from pipenv.vendor import click

console = rich.console.Console()
err = rich.console.Console(stderr=True)


def do_lock(
project,
Expand Down Expand Up @@ -62,21 +68,28 @@ def do_lock(

from pipenv.utils.resolver import venv_resolve_deps

# Mutates the lockfile
venv_resolve_deps(
packages,
which=project._which,
project=project,
category=pipfile_category,
clear=clear,
pre=pre,
allow_global=system,
pypi_mirror=pypi_mirror,
pipfile=packages,
lockfile=lockfile,
old_lock_data=old_lock_data,
extra_pip_args=extra_pip_args,
)
try:
# Mutates the lockfile
venv_resolve_deps(
packages,
which=project._which,
project=project,
category=pipfile_category,
clear=clear,
pre=pre,
allow_global=system,
pypi_mirror=pypi_mirror,
pipfile=packages,
lockfile=lockfile,
old_lock_data=old_lock_data,
extra_pip_args=extra_pip_args,
)
except RuntimeError:
sys.exit(1)

except Exception:
err.print(traceback.format_exc())
sys.exit(1)

# Overwrite any category packages with default packages.
for category in lockfile_categories:
Expand Down
Loading