can pants install binary build dependencies when r...
# general
c
can pants install binary build dependencies when running , building or packaging a target. For example, download and install golang when building go targets?
f
It depends on the language or tool.
Is your question about Go in particular?
c
Not particularly to any specific dependency but as general. Like in Bazel we can download packages using "http_archive" and write custom functions in starlark to achieve custom functionality. How can we do it in pants? For example, a python project requires tika parser jar server to run to parse pdf documents to extract text out of it. Java environment is required to run jar server. So one need to install jar, run the server and then init the package functionality. How can this be automated in Pants?
f
There are two issues there. (1) Can Pants rules download tools to run? (2) Can Pants be configured in BUILD files to download tools?
You seem to be asking about (2). There is actually a mechanism for that in recent Pants versions.
c
i need both... but please explain the 2nd too
f
The
adhoc_tool
target type available v2.16.x allows you to run any "runnable" target. https://www.pantsbuild.org/v2.16/docs/reference-adhoc_tool
A "runnable" target is generally any target which could have be run by
,/pants run
.
For JVM code, this includes
jvm_artifact
targets.
(I need to find docs to confirm that interpretation.)
c
thank you @fast-nail-55400 i will look into it
how can we define python funtions for buil targets as we can do in bazel?
that link points at the relevant part of the v2.16 release notes
how can we define python funtions for buil targets as we can do in bazel?
Do you mean like the Bazel "genrule" mechanism?
c
kind of
f
You can use
adhoc_tool
to invoke Python code via any of the target types:
pex_binary
,
python_requirement
,
python_source
, and
pyoxidizer_binary
And you can chain them together via the
execution_dependencies
field.
c
do we have a demo example?
f
h
Not sure if this is relevant, but you can also run Python code at BUILD file parsing time via macros: https://www.pantsbuild.org/docs/macros