You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Conforming with PEP 518 to use pyproject.toml instead of requirements.txt/setuptools #1366
Provide a clear description. Ex. I wish SAM CLI would [...]
I wish SAM CLI would utilize pyproject.toml for requirements. Subsequently, this would use additional package managers like poetry to in the sam build process.
Proposal
Add details of how to add this to the product.
Add functionality to read pyproject.toml when running sam build
This is pertinent to #1369 as well, we are trying to get reproducible builds within sam cli when creating our installers. What has your experience been like with poetry? Does it also allow for generation of pinned dependencies.
Reading about poetry, it seems to be pretty nice. @jfuss has also been looking into this recently. Might be another way to look at reproducible builds.
For adding functionality to read pyproject.toml for sam build, this could be another workflow in aws-sam-builders and sam build can choose that workflow in the future. Could you open an issue there as well?
@thesriram Thanks for the reply. Getting pinned requirements isn't bad. I have a python script that will read the poetry.lock files. Let me know if this is helpful. I've used this script to grep to a requirements.txt as a workaround for the time being.
import tomlkit
with open("poetry.lock") as f:
lock = tomlkit.parse(f.read())
for p in lock["package"]:
if not p["category"] == "dev":
print(f"{p['name']}=={p['version']}")
Reacted by Eric Bartels, Patrick Werz and Daniel Thurau
Reacted by Richard P. Field III, Dave Gallant, Daniel Thurau, Jake Brinkmann, Tom L, Ezequiel Birman, Mike Dalrymple, Jonathan Wren, Andrew McEdwards, Jason and 1 more
What likely needs to happen is a very similar workflow to the pip needs to be created but reads/uses the pyproject.toml file instead to determine what dependencies to be downloaded.
@jfuss, do you think it needs to be a separate workflow, or could the python_pip workflow be updated to allow use of the pyproject.toml file?
I did some really dirty testing to have SubprocessPip.main() call pip with args ["install", ".", "--target", ".aws-sam-foo"], and it seems to behave the same way as raw pip, in that it reads from [build-system] in pyproject.toml.
Do let me know if I've wandered off in the wrong direction.
Support poetry on a level where it exports the dependencies without hashes into a temporary requirements.txt file. And then let your current code consume this file?
My manual workflow currently is
poetry export --without-hashes > project/requirements.txt
sam build
Of course don't export it into the code directory but maybe into .aws-sam?
A workaround I found to install pyproject.toml based private Github dependencies is to sam build without them, install them manually via pip, then copy them into the build out directory.
sam build
pip install git+ssh://[email protected]/steventango/repository.git@main
cp -R /var/lang/lib/python3.12/site-packages/* .aws-sam/build/HelloWorldFunction
Presumably, if we aren't using Poetry and are just using the pip support for pyproject.toml via pip install ., we can use a tool like pigar or pipreqs to export a requirements.txt before our sam build step and use that?
The only issue I can see with some of our Lambdas is if you have custom pip indexes that you'd need to add.
We did this with --extra-index-url in the requirements.txt file before, but I am not sure if that is best practice. I suppose in that case you can prepend them to the generated requirements.txt with something like:
But expect it'd be better for those indexes to be added to the environment elsewhere, simplifying the workaround to just be generating the requirements.txt before the build time.
Activity
sriram-mv commentedon Aug 29, 2019
This is pertinent to #1369 as well, we are trying to get reproducible builds within sam cli when creating our installers. What has your experience been like with poetry? Does it also allow for generation of pinned dependencies.
Reading about poetry, it seems to be pretty nice. @jfuss has also been looking into this recently. Might be another way to look at reproducible builds.
For adding functionality to read pyproject.toml for
sam build, this could be another workflow in aws-sam-builders and sam build can choose that workflow in the future. Could you open an issue there as well?tcco commentedon Sep 30, 2019
@thesriram Thanks for the reply. Getting pinned requirements isn't bad. I have a python script that will read the
poetry.lockfiles. Let me know if this is helpful. I've used this script to grep to a requirements.txt as a workaround for the time being.ericofusco commentedon May 3, 2020
@tcco Poetry has a command to generate requirements.txt
CaptainDriftwood commentedon Feb 9, 2023
Has any progress been made on this feature request?
jfuss commentedon Feb 9, 2023
No progress on this front. This would be a change/addition to https://github.com/aws/aws-lambda-builders as that repo does all the heavy lifting.
Our pip integration is pretty custom: https://github.com/aws/aws-lambda-builders/blob/develop/aws_lambda_builders/workflows/python_pip/DESIGN.md to allow us to build for Lambda. What likely needs to happen is a very similar workflow to the pip needs to be created but reads/uses the
pyproject.tomlfile instead to determine what dependencies to be downloaded.HCrane commentedon Apr 14, 2023
Bump to move this feature a little along as we also would like to use it soon (TM). Best wishes to our friends at aws!
demolitionmode commentedon Aug 30, 2023
@jfuss, do you think it needs to be a separate workflow, or could the
python_pipworkflow be updated to allow use of thepyproject.tomlfile?I did some really dirty testing to have
SubprocessPip.main()call pip with args["install", ".", "--target", ".aws-sam-foo"], and it seems to behave the same way as raw pip, in that it reads from[build-system]inpyproject.toml.Do let me know if I've wandered off in the wrong direction.
crane-denny commentedon Oct 12, 2023
Maybe this is another solution:
Support poetry on a level where it exports the dependencies without hashes into a temporary requirements.txt file. And then let your current code consume this file?
My manual workflow currently is
Of course don't export it into the code directory but maybe into
.aws-sam?steventango commentedon Nov 8, 2024
A workaround I found to install
pyproject.tomlbased private Github dependencies is tosam buildwithout them, install them manually via pip, then copy them into the build out directory.LyndonArmitage commentedon Nov 27, 2024
Presumably, if we aren't using Poetry and are just using the
pipsupport forpyproject.tomlviapip install ., we can use a tool like pigar or pipreqs to export arequirements.txtbefore oursam buildstep and use that?The only issue I can see with some of our Lambdas is if you have custom
pipindexes that you'd need to add.We did this with
--extra-index-urlin therequirements.txtfile before, but I am not sure if that is best practice. I suppose in that case you can prepend them to the generatedrequirements.txtwith something like:But expect it'd be better for those indexes to be added to the environment elsewhere, simplifying the workaround to just be generating the
requirements.txtbefore the build time.