Skip to content
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
9 changes: 6 additions & 3 deletions aws_lambda_builders/workflows/python_pip/packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ def __init__(self, missing):
class NoSuchPackageError(PackagerError):
"""Raised when a package name or version could not be found."""

def __init__(self, package_name):
super(NoSuchPackageError, self).__init__("Could not satisfy the requirement: %s" % package_name)
def __init__(self, package_name, pip_error=None):
message = "Could not satisfy the requirement: %s" % package_name
if pip_error:
message += "\npip output:\n" + pip_error
super(NoSuchPackageError, self).__init__(message)


class PackageDownloadError(PackagerError):
Expand Down Expand Up @@ -926,7 +929,7 @@ def download_all_dependencies(self, requirements_filename, directory):
match = re.search(("Could not find a version that satisfies the " "requirement (.+?) "), error)
if match:
package_name = match.group(1)
raise NoSuchPackageError(str(package_name))
raise NoSuchPackageError(str(package_name), error)
raise PackageDownloadError(error)

# Extract local packages from pip output.
Expand Down
18 changes: 17 additions & 1 deletion tests/unit/workflows/python_pip/test_packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,23 @@ def test_raise_no_such_package_error(self, pip_factory):
pip.add_return((1, b"", (b"Could not find a version that satisfies the " b"requirement BadPackageName ")))
with pytest.raises(NoSuchPackageError) as einfo:
runner.download_all_dependencies("requirements.txt", "directory")
assert str(einfo.value) == ("Could not satisfy the requirement: " "BadPackageName")
assert str(einfo.value) == (
"Could not satisfy the requirement: BadPackageName\npip output:\n"
"Could not find a version that satisfies the requirement BadPackageName "
)

def test_preserve_ssl_failure_with_no_matching_distribution(self, pip_factory):
pip, runner = pip_factory()
stderr = (
b"Could not fetch URL https://pypi.org/simple/example/: "
b"SSLError: certificate verify failed - skipping\n"
b"ERROR: Could not find a version that satisfies the requirement example (from versions: none)\n"
b"ERROR: No matching distribution found for example"
)
pip.add_return((1, b"", stderr))
with pytest.raises(NoSuchPackageError) as einfo:
runner.download_all_dependencies("requirements.txt", "directory")
assert stderr.decode() in str(einfo.value)

def test_raise_other_unknown_error_during_downloads(self, pip_factory):
pip, runner = pip_factory()
Expand Down
Loading