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

Rez pip error handling improvements #1734

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
14 changes: 10 additions & 4 deletions src/rez/pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from rez.vendor.distlib.database import DistributionPath
from rez.vendor.packaging.version import Version as PackagingVersion
from rez.vendor.packaging.specifiers import Specifier
from rez.resolved_context import ResolvedContext
from rez.resolved_context import ResolvedContext, ResolverStatus
from rez.utils.execution import Popen
from rez.utils.pip import get_rez_requirements, pip_to_rez_package_name, \
pip_to_rez_version
Expand Down Expand Up @@ -124,8 +124,6 @@ def find_python_in_context(context):

Args:
context (ResolvedContext): Resolved context with Python and pip.
name (str): Name of the package for Python instead of "python".
default (str): Force a particular fallback path for Python executable.

Returns:
str or None: Path to Python executable, if any.
Expand All @@ -134,11 +132,19 @@ def find_python_in_context(context):
# Create a copy of the context with systems paths removed, so we don't
# accidentally find a system python install.
#
success = (context.status == ResolverStatus.solved)
if not success:
BryceGattis marked this conversation as resolved.
Show resolved Hide resolved
context.print_info(buf=sys.stderr)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a custom error message too? Something like "Failed to resolve ... "

return None

context = context.copy()
context.append_sys_path = False # #826

python_package = context.get_resolved_package("python")
assert python_package
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous this had a terrible traceback like this:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "D:\Code\rez\venv\Scripts\rez\rez-pip.exe\__main__.py", line 7, in <module>
  File "d:\code\rez\venv\Lib\site-packages\rez\cli\_entry_points.py", line 183, in run_rez_pip
    return run("pip")
           ^^^^^^^^^^
  File "d:\code\rez\venv\Lib\site-packages\rez\cli\_main.py", line 189, in run
    returncode = run_cmd()
                 ^^^^^^^^^
  File "d:\code\rez\venv\Lib\site-packages\rez\cli\_main.py", line 181, in run_cmd
    return func(opts, opts.parser, extra_arg_groups)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "d:\code\rez\venv\Lib\site-packages\rez\cli\pip.py", line 52, in command
    pip_install_package(
    py_exe, context = find_pip(pip_version, python_version)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "d:\code\rez\venv\Lib\site-packages\rez\pip.py", line 92, in find_pip
    py_exe, found_pip_version, context = find_pip_from_context(
                                         ^^^^^^^^^^^^^^^^^^^^^^
  File "d:\code\rez\venv\Lib\site-packages\rez\pip.py", line 201, in find_pip_from_context
    py_exe = find_python_in_context(context)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "d:\code\rez\venv\Lib\site-packages\rez\pip.py", line 141, in find_python_in_context
    assert python_package
AssertionError

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New output is much more useful:

resolve failed, by bryce@home, on Fri Apr 26 07:52:18 2024, using Rez v3.1.1

requested packages:
python-3.6
pip
~platform==windows           (implicit)
~arch==AMD64                 (implicit)
~os==windows-10.0.19045.SP0  (implicit)

The context failed to resolve:
The following package conflicts occurred: (python-3.7+ <--!--> python==3.6.8)

Resolve paths starting from initial requests to conflict:
  python-3.6 --> python-3.6.8
  pip --> pip-24.0 --> python-3.7+

To see a graph of the failed resolution, add --fail-graph in your rez-env or rez-build command.

07:52:18 WARNING  Found no pip in any python and/or pip rez packages!
07:52:18 WARNING  Falling back to pip installed in rez own virtualenv:
07:52:18 WARNING         pip: 23.2.1 (d:\code\rez\venv\Lib\site-packages\pip\__init__.py)
07:52:18 WARNING      python: 3.11.4 (d:\code\rez\venv\scripts\python.exe)
07:52:18 INFO     Installing 'elastic-transport==8.12.0' with pip taken from 'd:\\code\\rez\\venv\\scripts\\python.exe'
07:52:18 ERROR    ResolvedContextError: Cannot perform operation in a failed context

if not python_package:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this condition ever be true? If we resolved python and the solve was successful, context.get_resolved_package("python") should always return a python package no?

raise PackageNotFoundError(
f"python package family not found in context: {context}"
)

# look for (eg) python3.7, then python3, then python
name_template = "python{}"
Expand Down
Loading