abundant-analyst-12845
11/22/2022, 10:26 AMrefined-addition-53644
11/22/2022, 12:26 PMpython_awslambda
target inside each folder
• poetry has some nice features but you can use pants directly to manage all the dependencies. Pants can read the pyproject.toml and only pick the necessary dependencies for each lambda, So you can use a single source of dependencies. Read more here how pants manages 3rd party dependencies
Read this about python_awslambda
https://www.pantsbuild.org/docs/awslambda-pythonhappy-kitchen-89482
11/22/2022, 1:23 PMpoetry_requirements
target, and as @refined-addition-53644 says, Pants will take the correct subset of it for each lambda. That way you have a single consistent set of deps in the repo, but each lambda won’t have to package and ship stuff it doesn’t need. So basically you define the list of possible requirements using poetry syntax, but you let Pants use that list in its own way.abundant-analyst-12845
11/22/2022, 1:38 PMrefined-addition-53644
11/23/2022, 10:15 AM# my pants.toml
[python.resolves]
common = "3rdparty/python/common.lock"
# BUILD with poetry_requirements (should be where pyproject.toml is)
poetry_requirements(resolve="common")
# generate lockfile first by running
./pants generate-lockfiles --resolve=common
Also you don’t need to define local dependencies like the way poetry does. As long as you import that module/package in your lambda code, pants will package it for you.
In some cases where this doesn’t happen, you can do it explicitly when defining python_awslambda target. I would strongly recommend following the tutorials because I feel like they explain it better.abundant-analyst-12845
11/23/2022, 10:20 AMrefined-addition-53644
11/23/2022, 10:24 AMpython_sources
, python_test
or python_awslambda
where you want to fetch 3rd party packages from the common
resolve.
python_sources(resolve="common")
In order to avoid typing resolve in every target you can use ___defaults___
as explained here
I have something like this in my top level BUILD file
# define a default resolve for the all the targets below
__defaults__(all=dict(resolve="common"))
common
is very generic name. I don’t exactly use that name. So pick something more informative, if you would likepython_tests
if you want to run your tests using pants (which is recommended).abundant-analyst-12845
11/23/2022, 11:03 AM__defaults__(all=dict(resolve="common"))
poetry_requirements(
name="poetry",
resolve="common",
)
# The default `sources` field will include our handler file.
python_sources(name="lib")
python_awslambda(
name="lambda-one",
runtime="python3.9",
# Pants will convert this to `project.lambda_example:example_handler`.
handler="lambda_handler.py:lambda_handler",
)
output from running ./pants roots
.
lambda-one
lambda-two
shared-code
i get the following error when i run the package command either as
8:49.71 [ERROR] 1 Exception encountered:
Exception: Unmatched glob from CLI arguments: "lambda-one/lambda-one/lambda_handler.py"
Do the file(s) exist? If so, check if the file(s) are in your `.gitignore` or the global `pants_ignore` option, which may result in Pants not being able to see the file(s) even though they exist on disk. Refer to <https://www.pantsbuild.org/v2.14/docs/troubleshooting#pants-cannot-find-a-file-in-your-project>.
./pants package lambda-one/lambda_handler.py
14:58:33.04 [ERROR] 1 Exception encountered:
Exception: Unmatched glob from CLI arguments: "lambda-one/lambda_handler.py"
Do the file(s) exist? If so, check if the file(s) are in your `.gitignore` or the global `pants_ignore` option, which may result in Pants not being able to see the file(s) even though they exist on disk. Refer to <https://www.pantsbuild.org/v2.14/docs/troubleshooting#pants-cannot-find-a-file-in-your-project>.
refined-addition-53644
11/23/2022, 4:13 PMlambda-one/lambda_one
, you should run
./pants package lambda-one/lambda_one:<lambda_target_name>
# So in this case it should be
./pants package lambda-one/lambda_one:lambda-one
happy-kitchen-89482
11/23/2022, 4:28 PM/pants package lambda-one/lambda-one/lambda_handler.py
? That might work./pants package lambda-one/lambda_handler.py
won’t work because that path is not a correct path from the cwd to the file