https://pantsbuild.org/ logo
a

average-breakfast-91545

03/25/2023, 10:56 AM
Okay, so assuming I'm dumb enough to jump into building a plugin to build a lambda layer, with a week's "experience" of pants, how do I go about this? I've gone through the tutorial written by a friendly community member, and I've got a plugin that supports the package rule. I have a fieldset that takes a bunch of dependencies. All I need to do is: ā€¢ Create a temporary directory ā€¢ Copy each dependency to that temporary directory ā€¢ Create a zip of the directory I can see that there's a
dirutil
module that will create me a temp dir under the build root, but the docs are full of terrifying warnings about IO in rules. Is there something I need to be aware of here in order not to enrage the Cache Gods? From a thread in #general
f

fast-nail-55400

03/25/2023, 6:49 PM
Are the dependencies already available as one or more
Digest
s?
a

average-breakfast-91545

03/25/2023, 6:51 PM
At the moment I'm just trudging through code becoming increasingly confused. I can create a RequirementsPexRequest from my target, but I'm failing to create a Pex from that digest. Why do you ask?
I'm thinking that if I create a RequirementsPexRequest, then Get a Pex, I should be able to pass that digest to a Process and do the munging.
f

fast-nail-55400

03/25/2023, 7:27 PM
I ask because if the dependencies are already available as a
Digest
, then you can use the Digest-related API (i.e.,
CreateDigest
,
MergeDigests
,
AddPrefix
,
RemovePrefix
,
DigestEntries
,
DigestContents
) to manipulate the file system tree represented by the
Digest
into the form you need.
a

average-breakfast-91545

03/25/2023, 7:28 PM
That's my current plan, but f I try to Get(Pex, requirements_pex_request) I get an ast error, which I'm trying to puzzle out. I suspect it's because I'm running 2.15 but reading code from main
f

fast-nail-55400

03/25/2023, 7:28 PM
Because the Pants setup code needs to read the input and output types out of a
Get
When you have a variable with the input in it, you need to use the three-argument form of
Get
Get(OutputType, InputType, my_input)
a

average-breakfast-91545

03/25/2023, 7:29 PM
Ah ha. Excellent, so the places in the code I've seen using the 2 arg form are ... doing what?
I know that's a very stupid question
f

fast-nail-55400

03/25/2023, 7:29 PM
you will note that the two-argument form involves a constructor for the input type
and so the Pants setup code knows what the input type is (and can also just let the constructor call create the input instance)
a

average-breakfast-91545

03/25/2023, 7:30 PM
Roger, thank you. I'll give it a whirl
Just fixing a PC with my son šŸ˜‚
awesome, I have a pex in my process. Thank you so much for your patience.
f

fast-nail-55400

03/25/2023, 7:59 PM
I know that's a very stupid question
Not a stupid question; no software is ever obvious, let alone the Pants plugin API
šŸ‘ 1
h

happy-kitchen-89482

03/25/2023, 9:00 PM
Yeah, there are no stupid questions here, only incomplete documentation
šŸ˜‚ 1
a

average-breakfast-91545

03/25/2023, 9:51 PM
tbf, the documentation does make the difference between the two and three arg form clear, but I forgot all about that, and then had an inexplicable ast error.
f

fast-nail-55400

03/26/2023, 3:26 PM
Maybe the AST error should be improved to suggest the three-argument form in these cases?
for example, if the engine setup code sees the two-argument form but the second argument is a lower-cased identifier and thus likely not a Type, then the error could suggest the three-argument form.
a

average-breakfast-91545

03/26/2023, 4:22 PM
If I get sufficiently bored, I'll open an issue and a PR to make the suggested change. That would definitely have saved me some time.
2 Views