Skip to content

Suggest container builds for missing Python dependencies - #987

Open
dhunganapramod9 wants to merge 1 commit into
aws:developfrom
dhunganapramod9:fix/python-pip-container-hint
Open

dhunganapramod9 wants to merge 1 commit into
aws:developfrom
dhunganapramod9:fix/python-pip-container-hint

Conversation

@dhunganapramod9

@dhunganapramod9 dhunganapramod9 commented Dec 3, 2026 •

Copy link
Copy Markdown

Issue #, if available: #208

Description of changes

When the Python pip builder cannot package a dependency, keep the dependency details and add a conditional hint for native compilation. The hint suggests a Lambda-compatible Linux environment and points SAM CLI users to sam build --use-container. Other pip packaging errors keep their existing message.

Description of how you validated changes

  • Reproduced the failure through LambdaBuilder on Windows with Python 3.12 and a local wheelhouse containing only the Windows wheel for MarkupSafe 3.0.3. Both versions report the missing dependency. The patch adds the container hint.
  • Python pip unit and functional suites passed (204 passed, 1 skipped). The new regression case failed before the fix and passed with it.
  • Ruff, Black, and git diff --check passed. The full local unit and functional run reached 94.39% coverage and had the same 24 failures as unmodified develop on this Windows machine.

Checklist

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@dhunganapramod9
dhunganapramod9 requested a review from a team as a code owner December 3, 2026 19:55

@bnusunny bnusunny left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for picking up #208. The change is small and safe: only MissingDependencyError gets the hint, every other PackagerError keeps its current message, and the original error stays chained (from ex). The parameterized test covers both paths, and CI is green. Approving.

Non-blocking suggestions, fine as follow-ups:

  1. Readable dependency list. MissingDependencyError is raised with packages_without_wheels, a set of Package objects, and it doesn't pass a message to super().__init__, so str(ex) is the raw set repr (e.g. {markupsafe==3.0.3(sdist)}). That predates this PR, but now that the message is user-facing, consider formatting ex.missing as a list of names before the hint.
  2. Hint inside a container build. If the user already runs sam build --use-container, a missing wheel isn't a host-platform problem, and "try sam build --use-container" points the wrong way. lambda-builders can't tell, so softer wording such as "If you are not already building in a container..." would avoid that.
  3. Machine-readable errors. SAM CLI's sam build --output json reports failures as {"error": {"type", "message", "resources"}}, where type is the lambda-builders exception class name. Because Workflow.run re-wraps every ActionFailedError into WorkflowFailedError, this case shows up as "type": "WorkflowFailedError", the same as any other build failure, and the hint and package list exist only as free text in message. For agents and scripts to act on it, a follow-up could carry a distinct error type (e.g. keep MissingDependencyError, with missing as a list of names) through the workflow so SAM CLI can expose it, and let SAM CLI add the --use-container suggestion as its own field, since it knows whether the build already ran in a container. Not needed for this PR.
  4. Test input. The test builds MissingDependencyError(["native-package==1.0"]) from a list; build_dependencies actually raises it with a set of Package objects. A case using that shape would cover point 1.

Please also add Fixes #208 to the description so the issue closes on merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants