mammoth-dawn-85816
08/28/2025, 1:39 PMpants package src/lambdas/whatever I get a little bit of metadata:
14:37:05.54 [INFO] Wrote dist/src.lambdas.whatever/whatever.zip
Runtime: python3.12
Architecture: x86_64
Handler: lambda_function.handler
Is there any way to have that metadata output to a file instead? (My bash is weaker than I thought it was, I don’t seem to be able to pipe it to a file from stdout or stderr either!)
I’d like to be able to configure my terraform to set up my lambda with the runtime, arch, and handler as configured in pants, so I don’t have duplicate info — if I can get this into a JSON/similar file, I can configure Terraform to read it and use those values 💪square-psychiatrist-19087
08/28/2025, 2:08 PMpants peekmammoth-dawn-85816
08/28/2025, 3:12 PMhandler , and architecture, but the Python version is set at the monorepo level, so I presume it’s not pulled up to being able to peek at the target?
[python]
interpreter_constraints = ["==3.12.*"]
If it’s useful, here’s the jq command for extracting the handler & architecture:
pants peek src/lambdas/whatever | jq '.[] | select(.target_type == "python_aws_lambda_function") | {handler: (.handler | sub("\\.py:"; ":")), architecture}'
I’ll keep hunting for ways to pull the runtime version out — I don’t really want to have to specify it in the BUILD for every lambda (as the whole point here is to minimize duplicate config)mammoth-dawn-85816
08/28/2025, 3:23 PMpyproject.tml via poetry… I’ll keep going 😊square-psychiatrist-19087
08/28/2025, 3:42 PM__defaults__(all=dict(interpreter_constrains=["==3.12.*"]))
Then it should show up in peek outputmammoth-dawn-85816
08/28/2025, 4:05 PMinterpreter_constraints in the pants.toml not do the same?
(I don’t have a root BUILD at the moment, but I could make one for defaults — it just seems odd to not have the interpreter constraints in the pants.toml not be used here?)square-psychiatrist-19087
08/28/2025, 4:11 PMif target.interpreter_constraints is not None:
return target.interpreter_constraints
else:
return config.interpreter_constraints
So if the target doesn't have interpreter constrains it will look it up in pants.toml. However, pants peek can't do that and only looks at target values.
This __defaults__ trick sets the value on the target, so it becomes visible to pants peekmammoth-dawn-85816
09/06/2025, 8:56 AMpants peek, regardless of where I define my contraints:
• as a default in my root BUILD (as you describe above)
• with python_sources(interpreter_constraints=["==3.12.*"]) in my lambda’s BUILD
• in the pants.toml in the [python] section as an interpreter_constraints parameter
• in the lambda’s pyproject.toml (as a poetry dependency, used with a poetry_requirements in the lambda’s BUILD)
I can get most of what’s output with pants package src/lambdas:: with jq and pants peek, but not everything:
$ pants package src/lambdas::
09:50:12.32 [INFO] Wrote dist/src.lambdas.whatever/whatever.zip
Runtime: python3.12
Architecture: x86_64
Handler: lambda_function.handler
$ pants peek src/lambdas:: | jq '.[] | select(.target_type == "python_aws_lambda_function") | {path: (.address | sub(":.*$"; "")), handler: (.handler | sub("\\.py:"; ".")), architecture}'
{
"address": "src/lambdas/whatever",
"handler": "lambda_function.handler",
"architecture": "x86_64"
}
(I also have to do extra bash to split the records & convert address into the output path dist/src.lambdas.whatever/whatever.json for each of the results pants peek returns)mammoth-dawn-85816
09/06/2025, 8:57 AMlocals {
lambda_base = "../dist/src.lambdas.whatever/whatever"
lambda_config = jsondecode(file("${lambda_base}.json"))
}
resource "aws_lambda_function" "whatever_lambda" {
function_name = "whatever_lambda"
handler = local.lambda_config.handler
runtime = local.lambda_config.runtime
architectures = [local.lambda_config.architecture]
filename = "${lambda_base}.zip"
source_code_hash = filebase64sha256("${lambda_base}.zip")
}
Is there a way of doing this I’m missing? Or a good place for me to make this request of the pants team?square-psychiatrist-19087
09/06/2025, 9:02 AMruntime for your lambda?
https://www.pantsbuild.org/stable/reference/targets/python_aws_lambda_functionsquare-psychiatrist-19087
09/06/2025, 9:03 AMsquare-psychiatrist-19087
09/06/2025, 9:04 AMruntime , it should be visible in pants peekmammoth-dawn-85816
09/06/2025, 9:11 AMpyproject.toml, which is calculated by inference by pants package and output to the terminal), and once in my BUILD for in python_aws_lambda_function(runtime="python3.12").
Any ideas on how to get peek to output the inferred python runtime?square-psychiatrist-19087
09/06/2025, 9:12 AMdependencies or handler?square-psychiatrist-19087
09/06/2025, 9:18 AMpython_version = "3.12"
__defaults__(all=dict(
interpreter_constraints=[f"=={python_version}.*"],
runtime=f"python{python_version}",
))square-psychiatrist-19087
09/06/2025, 9:25 AM#!/bin/bash
export PYTHON_REQUIRES=$(grep python_requires pyproject.toml)
Then in BUILD:
python_requires = env('PYTHON_REQUIRES')
# then parse it and use itmammoth-dawn-85816
09/06/2025, 9:26 AMsquare-psychiatrist-19087
09/06/2025, 9:30 AMsquare-psychiatrist-19087
09/06/2025, 9:34 AMbut I’m going to have multiple pythons in my monorepo 😔
You could try inferring this from dependencies then, you could do pants peek on your lambda and get
dependencies from it. Then inside dependencies find python_source it depends on and do pants peek on python_source, it should have interpreter_constraints in itmammoth-dawn-85816
09/06/2025, 9:47 AMpoetry to manage my python version?
I’ve put all the relevant bits in this gist (note that I’ve switched to python 3.13 since we started this conversation).
I’ve got to duck out for the rest of the day — so I won’t be able to reply for a while, but thanks for your help & thoughts!happy-kitchen-89482
09/07/2025, 2:05 AMhappy-kitchen-89482
09/07/2025, 2:06 AMhappy-kitchen-89482
09/07/2025, 2:09 AMhappy-kitchen-89482
09/07/2025, 2:11 AMhappy-kitchen-89482
09/07/2025, 2:11 AMdist as well just above thathappy-kitchen-89482
09/07/2025, 2:15 AMhappy-kitchen-89482
09/07/2025, 2:15 AMhappy-kitchen-89482
09/07/2025, 2:15 AMhappy-kitchen-89482
09/07/2025, 2:16 AMhappy-kitchen-89482
09/07/2025, 2:16 AMhappy-kitchen-89482
09/07/2025, 2:16 AMhappy-kitchen-89482
09/07/2025, 2:58 AMmammoth-dawn-85816
09/07/2025, 11:11 AMhappy-kitchen-89482
09/09/2025, 4:38 AMhappy-kitchen-89482
09/09/2025, 6:23 PMhappy-kitchen-89482
09/11/2025, 5:08 PMmammoth-dawn-85816
09/12/2025, 1:33 PMmammoth-dawn-85816
09/12/2025, 1:38 PMhappy-kitchen-89482
09/12/2025, 8:28 PMscie-pants itself. The current scie-pants version should be able to upgrade Pants to 2.28mammoth-dawn-85816
09/17/2025, 9:01 PMSCIE_BOOT=update pants
pants help
scie-pants 0.12.3 to 0.12.5), but pants help still shows:Pants 2.27.0
SCIE_BOOT=xxxx pants, rather than (pants upgrade or similar) — so the chances are very hight this is a pebkac!pants.toml then pants very correctly provides that version 😂happy-kitchen-89482
09/17/2025, 10:17 PM