Hello. We are trying to write a shell scriptsthat ...
# general
a
Hello. We are trying to write a shell scriptsthat wraps an execution of a few python binaries. e.g., something like -
Copy code
script.sh

./proj/main.py | ./proj/main2.py | ./proj/main3.py
How can i achieve this with pants? (We looked at
shell_source
, but it does not appear to be a runnable target. Also shunit2_test is almost what we need, except this is not a test in our case)
b
If shell source isn't runnable, it should be 😬
a
a
@bitter-ability-32190 i tend to agree 🤷‍♂️ (this is pants 2.16)
@acoustic-house-77496 i'm not sure which part would be useful to me:)
b
Feel free to open annussue
a
I mean you can include an external tool and use it with a goal_rule or create a dedicated target
But I’m new to pants so I may be wrong, I just used that guide to use my external tool
a
Thanks @acoustic-house-77496, i'll look into it:) I can't not wonder though - i'm probably missing something very basic. Isn't running shell scripts a common use case?
a
If you want just to invoke it on demand you can create a ‘@goal_rule’ and use the external tool there
a
I'm hoping to find a bit simpler solution, as this seems to be a bit of an overkill for my case. But let's see 🙂
b
Until recently-ish sources were thought of to be something that goes into a runnable thing (think Java) Scripts, of course occupy both, but unless PRs are made, things don't change 🙂
run_shell_command
would be your runnable thing for shell
a
Thank you!
run_shell_command
worked. The key was to use
CHROOT
which i previously missed.
And
shell_soutces
makes more sense to me now, given the context you added.
b
You may also be able to use
runnable_dependencies
https://www.pantsbuild.org/docs/reference-run_shell_command#coderunnable_dependenciescode as part of
run_shell_command
a
seems like a
pex_binary
cannot be specified as a
runnable_dependency
.. Output:
Copy code
❯ pants run stimulus/flask_server:my_script
11:40:27.52 [ERROR] 1 Exception encountered:

Engine traceback:
  in `run` goal

ValueError: Address `stimulus/flask_server:app` was specified as a runnable dependency, but is not
runnable.
BUILD.pants:
Copy code
python_sources()

 pex_binary(
   name="app",
   entry_point="server.py",
 )

 shell_sources(name="shell-scripts")

 run_shell_command(
     name="my_script",
     command="my-script.sh",
     runnable_dependencies=[":shell-scripts", ":app"]
 )