:wave: hi folks….big fan….I’m sure this has been ...
# general
s
👋 hi folks….big fan….I’m sure this has been asked plenty of times, but I’m struggling to find it in the slack or docs, but if I want to run a pex binary to produce an artifact (like a file) that is then consumed by another pex binary, how could I build that?
Eeek, maybe my asking is premature, I think
adhoc_tool
might be what I need
oooo, that looks perfect!
b
yeah, adhoc_tool is good for this! shell_command (and passing the pex as a
runnable_dependencies
can be handy too)
s
sweet! Excited to give this a whirl
Hmmm, I setup
adhoc_tool
but I’m struggling to invoke it. When I run `pants run :my_target (which is an adhoc_tool) I get the error
Copy code
* docker_image
  * pex_binary
  * python_requirement
  * python_source
  * python_test
  * run_shell_command
  * system_binary
ok, looking at the javascript demo was helpful as I could see it requires using the
run_shell_command
to invoke the adhoc_tool (code) — and specifically I saw in the README
pants run javascript:run-js-app
b
ah, yeah,
adhoc_tool
is for creating files (i.e. doing code-generation) for other Pants targets to consume. If you want to package up a helper command that can be run by humans on demand, then
run_shell_command
(or the
pex_binary
itself with
args
https://www.pantsbuild.org/prerelease/reference/targets/pex_binary#args ) is better
👍 1
s
ok, another question….as I’m getting much further. How can I pass an env var the
args
field of adhoc_tool?
ie….
Copy code
adhoc_tool(
    name="package-tar",
    runnable=":my-pex",
    output_dependencies=[":my-pex"],
    args=[
        "--image",
        "docker-repo/my-service:{env.BRANCH_DATE_TAG}",
    ],
    root_output_directory=".",
    extra_env_vars=["BRANCH_DATE_TAG"]
)
b
there's an
env
function, e.g.:
f"docker-repo/my-service:{env('BRANCH_DATE_TAG')}"
s
I was trying that and I didn’t see it working…started digging into the code and I saw this line which made me think it wouldn’t work — and when I run it I get my value (from the debug statement) ….
{env.BRANCH_DATE_TAG}'"], env: {"BRANCH_DATE_TAG": "bennett-test2"}
I could pass this also to pex_binary as an argument if that would work
b
(Did you notice that that's calling
env("...")
with an f-string, rather than
{env.
substitution?)
s
sorry, I misssed that…that’s so cool!
works amazing! Thank you!