happy-fish-67882
11/23/2020, 11:49 PMbash -n
<scriptname> ?
Also, any way I can do more tests like validate output of running flags for the script on the command line?witty-crayon-22786
11/23/2020, 11:56 PMwitty-crayon-22786
11/23/2020, 11:56 PMwitty-crayon-22786
11/23/2020, 11:56 PMhappy-fish-67882
11/23/2020, 11:57 PMwitty-crayon-22786
11/23/2020, 11:57 PMhappy-fish-67882
11/23/2020, 11:57 PMhappy-fish-67882
11/23/2020, 11:58 PMwitty-crayon-22786
11/23/2020, 11:58 PMwitty-crayon-22786
11/23/2020, 11:58 PMhappy-fish-67882
11/23/2020, 11:59 PMhundreds-father-404
11/23/2020, 11:59 PMI’d like to add a shell script test to ensure it passes basic testMight it be possible to write a light-weight Python wrapper that calls the relevant bash commands with
subprocess.run()
, then running that via ./pants test
and a python_tests()
target?witty-crayon-22786
11/23/2020, 11:59 PMwitty-crayon-22786
11/24/2020, 12:00 AMtest
didn’t depend on binary
, so your binary might not be availablewitty-crayon-22786
11/24/2020, 12:00 AMwitty-crayon-22786
11/24/2020, 12:01 AMhappy-fish-67882
11/24/2020, 12:01 AMwitty-crayon-22786
11/24/2020, 12:02 AMhundreds-father-404
11/24/2020, 12:03 AMbut in v1, test didn’t depend on binary, so your binary might not be availableTrue. But in v1, expressing that type of dependency between
test
and binary
is non-trivial, right? That was a prime reason we implemented the v2 engine in the first place
Martin, how feasible would it be to have an outer bash script that calls several Pants commands to achieve what you’re hoping for? Very clunky indeed, but I don’t want to lead you astray with a v1 plugin if you don’t need it. They’re harder to write and not as well documentedwitty-crayon-22786
11/24/2020, 12:03 AMhappy-fish-67882
11/24/2020, 12:05 AMhappy-fish-67882
11/24/2020, 12:06 AMhundreds-father-404
11/24/2020, 12:07 AMFor v2 -- node and scala don’t seem supportedAre you using Python too? It’s possible to set it up so that the Python portion of your repo uses Pants 2.0+, but the rest of your repo still uses 1.30 Not sure if the functionality you’re looking for is around Scala/Node, though. If so, probably not helpful. https://www.pantsbuild.org/docs/how-to-upgrade-pants-2-0#step-2-setup-jvm-node-and-go-support-if-relevant
happy-fish-67882
11/24/2020, 12:07 AMwitty-crayon-22786
11/24/2020, 12:08 AMhappy-fish-67882
11/24/2020, 12:20 AMwitty-crayon-22786
11/24/2020, 12:21 AMhappy-fish-67882
11/24/2020, 12:21 AMhundreds-father-404
11/24/2020, 12:23 AMbut what pants command would those be to do what I’d like to wrt bash script inclusion/testing thoughThis is the part we gotta figure out. I’m trying to understand your workflow. Are you hoping to do something like this?
$ ./pants package path/to:tgt
$ result=$(dist/result.pex arg1 --arg2)
$ assert result == foo
happy-fish-67882
11/24/2020, 6:37 PMhappy-fish-67882
11/24/2020, 6:38 PMhappy-fish-67882
11/24/2020, 6:39 PMhundreds-father-404
11/24/2020, 6:40 PM./pants bundle
or ./pants binary
. Both of those got consolidated into ./pants package
in 2.0
Generally, I’m trying to see if this is what you’re hoping to do: build a binary with Pants, then run a script that does something with that built artifact, such as testing that it works correctly. Something like this: https://www.pantsbuild.org/v2.2/docs/python-test-goal#depending-on-packageshundreds-father-404
11/24/2020, 6:41 PM<myscript.sh>
does?happy-fish-67882
11/24/2020, 6:42 PMhappy-fish-67882
11/24/2020, 6:44 PMhundreds-father-404
11/24/2020, 6:44 PM./pants binary
- sounds like a red herring. Sorry about that
Taking a step back, you have <myscript.sh>
, and the goal is to use Pants to test that <myscript.sh>
works properly. Is that right? You are not trying to rewrite <myscript.sh>
, only test is.happy-fish-67882
11/24/2020, 6:45 PMhappy-fish-67882
11/24/2020, 6:45 PMhappy-fish-67882
11/24/2020, 6:46 PMhundreds-father-404
11/24/2020, 6:47 PMmyscript.sh
import subprocess
def test_script():
result = subprocess.run(["myscript.sh", "arg1"], stdout=suprocess.PIPE, ...)
assert "foo" in result.stdout.decode()
Then, you could use a python_tests()
target to have Pants always run these tests. How does that sound?happy-fish-67882
11/24/2020, 6:47 PMhappy-fish-67882
11/24/2020, 6:48 PMhappy-fish-67882
11/24/2020, 6:48 PMhappy-fish-67882
11/24/2020, 6:48 PMhundreds-father-404
11/24/2020, 6:49 PM<build root>/test_myscript.py
, or some people like to have a build-support
folder for things like this. Wherever you define that Python file, you’ll have a BUILD file with a target like this in it:
python_tests(name="tests")
hundreds-father-404
11/24/2020, 6:50 PMsince it’s pythonIt is Python, but extremely limited Python. For example, import statements are banned. BUILD files are nothing more than a declarative way to describe metadata for some code - they’re intentionally very limited You use macros and/or plugins to add new functionality to Pants
happy-fish-67882
11/24/2020, 6:51 PMhappy-fish-67882
11/24/2020, 6:51 PMhappy-fish-67882
11/24/2020, 6:52 PMhundreds-father-404
11/24/2020, 6:52 PMGoal would be to flag through pants if there’s any syntax errors in it,Have you heard of Shellcheck? Our example plugin repo has an implementation of it. If you’re interested, we can help wire it up into your repo - mostly just copy pasta 🙂 Shellcheck has saved me so much headache We also have implemented a unit testing framework for bash called shunit2
happy-fish-67882
11/24/2020, 6:54 PMhappy-fish-67882
11/24/2020, 6:54 PMhundreds-father-404
11/24/2020, 6:57 PMhappy-fish-67882
11/24/2020, 7:14 PM