Hi, I have a use case where I would like to create...
# general
b
Hi, I have a use case where I would like to create an "uberzip" of a subset of zip files generated and stored in dist/, what would be an elegant way of doing this?
g
dist/
is output-only, but I'd investigate using https://www.pantsbuild.org/stable/reference/targets/archive to bundle up multiple things.
b
Yeah so the output zips that I want to combine are created from
python_aws_lambda_function
. Was hoping for some clever way to reference the built artifacts.
g
Does it not work to put those in the
packages
field of the archive target? I'd expect that to package those lambda functions, then embed those into the archive.
b
Yep, seems to work! Thanks
But I can't specify
target()
there it seems, yields zip error:
zip error: Missing or empty zip file
, would be ideal given I have multiple lambda functions as targets. Perhaps there's a better way? Sorry for the newbie questions
g
Ah, yeah, I don't think a
target
supports packaging... Are you doing something like this?
Copy code
python_aws_lambda_function(
    name="a",
)

python_aws_lambda_function(
    name="b",
)

python_aws_lambda_function(
    name="c",
)

target(
    name="all",
    dependencies=[":a", ":b", ":c"]
)

archive(
     name="bundle",
     packages=[":all"]
)
b
yup
g
I think this does what you expect, without using an intermediate target
Copy code
python_aws_lambda_function(...) # etc

all_lambdas = [":a", ":b", ":c"]

archive(
     name="bundle",
     packages=all_lambdas,
)
b
👀 Can I reference the all_lambdas variable from a BUILD file one level up? It's what I'm doing today as the "megazip" may include other things from that "level" in the hierarchy
(i mean it's fine to explicitly list them all in the top directory BUILD, would just be elegant to do it in the BUILD where the function code lives, hence my attempt to use target())
g
Ah, hm. No. I don't think there's any mechanic for doing that. All build files are handled in isolation, so you can only reference other targets via their address, and no variables etc. You could maybe do something with a macro file like this:
Copy code
# macros.py
def all_lambdas():
    return ["//src/python/lambda1:package", "//src/python/lambda2:package"]

# whatever/BUILD
archive(
    name="bundle",
    packages=all_lambdas()
)
A macro file works a bit like "builtins" in Python, so it runs before the build file itself and imports all symbols. So you'd have the same all_lambdas function everywhere. I'm not aware if variables are visible from macro files, but maybe that does.
b
Thanks @gorgeous-winter-99296, this is useful