Hi all! Is it possible to package a shell script? ...
# general
s
Hi all! Is it possible to package a shell script? I've added the shell_source target but it doesn't work with
pants package
. And I don't understand how to test it, shunit2 test can't find the shell script in order to run it
b
What result are you wanting from
pants package
? The shell script copied to
dist/
? For tests, what’s the BUILD file definitions you’re using? And what’s the (attempted) invocation if the script in tests?
c
if you were hoping to get the scripts bundled up in an archive, then there’s a target you need to declare that does that: https://www.pantsbuild.org/docs/reference-archive
s
Ideally I want a magical package something like
pex_binary
that would store my shell script with all the dependencies:
Copy code
pex_binary("my-python-script")
shell_binary("my-shell-binary", dependencies=[":my-python-script"])
then I would do
pants package my-shell-binary
and then I would execute
./dist/my-shell-binary
and it would run my script and the script would have access to pex_binary that I declared as a dependency
c
you can do that, you just need to tweak it slightly, as the pex will be the “top level” packageable thing, and also the executable you start with going into it..
i.e. have the shell script as
resources
for your pex instead of the other way around..
s
or you mean manually package shell script as a resource, then load it in python and execute with subprocess.run or smth
c
I’m not exactly sure how to invoke the shell scripts from the pex. It may work using that
script
field, but what I was referring to was that in order to get the shell scripts into the pex, you need to add them as a resource dependency for your pex binary first.
s
yeah, but it's kinda hacky, what if I want to access 2 pexes in my bash script? what if I want to access a pex and a jar that I got from
deploy_jar
?
c
if you want the scripts to be first class, I guess the way to go is with
archive
and unpack that and execute the scripts as you envisioned, and have the jars and pex binaries and what not be part of that archive.
s
ok, thanks! I'll try that
👍 1
I found a tool for that https://github.com/megastep/makeself/ Maybe I'll do a plugin for it
👍 1