Skip to content

Feature request: Add support for pyproject.toml #688

Open
@pkarakal

Description

@pkarakal

Describe your idea/feature/enhancement

As the Python ecosystem moves towards pyproject.toml as the standard for defining build system requirements and managing dependencies, it would be highly beneficial if there was a lambda builder to recognize and handle this file natively. Using setup.py is gradually being phased out in favor of pyproject.toml which modern package managers (like Poetry) support to align with PEP 517 and PEP 518 standards.

Currently, we either have to manually export our dependencies to a requirements.txt file, or have makefile as the build method in the template.yaml where the makefile is exporting the deps to a requirement.txt before preparing the function:

# template.yaml
Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: hello_world/
      Handler: app.lambda_handler
      Runtime: python3.12
    Metadata:
      BuildMethod: makefile
build-HelloWorldFunction:
  poetry export -f requirements.txt --output requirements.txt --without-hashes
  pip install --target "$(ARTIFACTS_DIR)" -r requirements.txt
  cp -r *.py $(ARTIFACTS_DIR)

This can be tedious when having to deal with multiple functions.

Proposal

Implement a builder, similar to python_pip that parses pyproject.toml, recognizes the build-backend defined in pyproject.toml (such as poetry or flit) and handles dependencies installation accordingly. This way when invoking sam build the existence of pyproject.toml is also taken into consideration (and not only requirements.txt and setup.py). Based on this, it should be able to select the appropriate builder to use.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions