From e74c71e66afcef97889900b31cfd5642f14eae6c Mon Sep 17 00:00:00 2001 From: Bryce Gattis Date: Fri, 26 Apr 2024 07:53:40 -0500 Subject: [PATCH 1/2] Add error handling for failed resolve and improve error handling if python package not found in resolve Signed-off-by: Bryce Gattis --- src/rez/pip.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/rez/pip.py b/src/rez/pip.py index 1703bb567..fe67fd6fb 100644 --- a/src/rez/pip.py +++ b/src/rez/pip.py @@ -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 @@ -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. @@ -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: + context.print_info(buf=sys.stderr) + return None + context = context.copy() context.append_sys_path = False # #826 python_package = context.get_resolved_package("python") - assert python_package + if not python_package: + raise PackageNotFoundError( + f"python package family not found in context: {context}" + ) # look for (eg) python3.7, then python3, then python name_template = "python{}" From c4bbf81a5cca841a325ec586d1829b3152f2efc4 Mon Sep 17 00:00:00 2001 From: BryceGattis <36783788+BryceGattis@users.noreply.github.com> Date: Thu, 23 May 2024 06:28:48 -0500 Subject: [PATCH 2/2] Update src/rez/pip.py Co-authored-by: Jean-Christophe Morin <38703886+JeanChristopheMorinPerso@users.noreply.github.com> Signed-off-by: BryceGattis <36783788+BryceGattis@users.noreply.github.com> --- src/rez/pip.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/rez/pip.py b/src/rez/pip.py index fe67fd6fb..914915c26 100644 --- a/src/rez/pip.py +++ b/src/rez/pip.py @@ -132,8 +132,7 @@ 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: + if context.status != ResolverStatus.solved: context.print_info(buf=sys.stderr) return None