I have a `pex_binary` target in a BUILD file (a ut...
# plugins
p
I have a
pex_binary
target in a BUILD file (a utility script used to maintain an in-repo file). I want a
@rule
to run that target. What's the best way to get that pex? Surely there's a way to request a pex from a given target, right? The only slightly related thing I found in the docs was https://www.pantsbuild.org/docs/rules-api-installing-tools#pex-install-binaries-through-pip But this is not an external / installed tool. It's entirely in-repo.
āœ… 1
b
Just
await
the
BuiltPackage
to get the built thing. Or if you just wanna run it you could request a
RunRequest
and run it yourself (similar to how the
run
goal works
p
ugh. Declaring a
pex_binary
target will make
./pants package ::
build it?
b
As of today, yes
p
I haven't done anything with packaging yet, so that's a blind spot I have.
b
Which isn't great. Prior to my google doc, a
pex_binary
was the only way to run "scripts". But once thats in that will change (after a deprecation cycle)
p
I have a python script, it imports various other python sources from the project to extract info from them (thus it requires venv-ish something). I just want my rules to run the file in a virtualenv and give me the stdout. šŸ˜• I feel like I'm building a lot of boilerplate to "just" run a script.
So, would it be better to define the "Pex" in my plugin instead of as a
pex_binary
in BUILD? If so, got any hints for building a pex from local files + deps?
b
Well there's two parts here: • If you want to "just run a script" and it to work, then you can
./pants run path/to/file.py
and if there's a
pex_binary
with the
entry_point
set to the file, you're golden • If you want to run this in a plugin, then the world is your oyster, but you have to do the groundwork
p
I don't want to run it, I want a rule to run it, so the
run
goal doesn't help me here.
ah. That's your second point.
b
Then you technically don't need a
pex_binary
target
p
Great. Got any examples of Pex-ifying a script (in a plugin)? I feel it should be obvious but my brain is a bit mushy today. šŸ˜•
b
Yeah the rule-based PEX support is a bit... tangled. So mushy brain is to be expected
The root of your solution lies around making a
PexFromTargetsRequest
and turning it into a PEX
p
cool. I will grep the pants code for
PexFromTargetsRequest
which I haven't seen before. Thank you for the tip!
b
From that, you can (probably) make a
VenvPex
->
VenvPexProcess
->
Process
->
ProcessResult
If you start pulling hairs, let us know
p
Will do. Thanks!