in aws_lambda_builders/workflows/python_pip/actions.py [0:0]
def _find_runtime_with_pip(self) -> Tuple[SubprocessPip, str]:
"""
Finds a Python runtime that also contains `pip`.
Returns
-------
Tuple[SubprocessPip, str]
Returns a tuple of the SubprocessPip object created from
a valid Python runtime and the runtime path itself
Raises
------
ActionFailedError
Raised if the method is not able to find a valid runtime
that has the correct Python and pip installed
"""
binary_object: Optional[BinaryPath] = self.binaries.get(self.LANGUAGE)
if not binary_object:
raise ActionFailedError("Failed to fetch Python binaries from the PATH.")
for python_path in binary_object.resolver.exec_paths:
try:
valid_python_path = binary_object.validator.validate(python_path)
if valid_python_path:
pip = SubprocessPip(osutils=self._os_utils, python_exe=valid_python_path)
return (pip, valid_python_path)
except (MisMatchRuntimeError, RuntimeValidatorError):
# runtime and mismatch exceptions should have been caught
# during the init phase
# we can ignore these and let the action fail at the end
LOG.debug(f"Python runtime path '{python_path}' does not match the workflow")
except MissingPipError:
LOG.debug(f"Python runtime path '{python_path}' does not contain pip")
raise ActionFailedError("Failed to find a Python runtime containing pip on the PATH.")