https://pantsbuild.org/ logo
#general
Title
# general
b

billowy-motherboard-58443

09/29/2020, 5:40 PM
Hello - whole new "how do I do this in Pants?"
given a tree which is a bunch of library packages, with "core", "util", "web", etc..
if we have the idea that with company namespace "ns"
let's say, ns.core.leaderElection contains code with the interfaces for doing leader election
and ns.leaderElection.cassandra has the backend-specific code
in the tree, ns/leaderElection/casssandra.py
and e.g. ns/leaderElection/zookeeper.py
so that an end user would
Copy code
pip3 install ns.core
pip3 install ns.leaderElection.casssandra
and then
Copy code
from ns.leaderElection.cassandra import CassandraElector
which in turn would have a dependency on
Copy code
ns.core.leaderElection
ok, that was all stage setting
Q: in ns/leaderElection/BUILD, would I have two (2)
python_library()
and two (2)
python_distribution()
declarations - one each for the cassandra and zookeeper implmentations?
[done]
w

witty-crayon-22786

09/29/2020, 5:59 PM
yes, i believe so.
and unfortunately, because you’d have two+ targets in one directory, you’d need to manually specify more information on each target: the
sources
as well as the
name
pants tries to use the directory structure to minimize boilerplate, but having multiple sets of metadata in one directory makes that harder
h

hundreds-father-404

09/29/2020, 6:13 PM
Something like:
Copy code
python_library(
  name="cassandra",
  sources=["f1.py", "f2.py"],
)

python_library(
  name="zookeeper",
  sources=["f3.py", "f3.py"],
)
b

billowy-motherboard-58443

09/29/2020, 6:25 PM
yes, the sources bit makes sense
in that case though, wouldn't
setup-py ns/leaderElection
cause both pkgs to be built?
or does one specify the target with e,g,
setup-py ns/leaderElection:cassandra
h

hundreds-father-404

09/29/2020, 6:29 PM
setup-py ns/leaderElection
is shorthand for
setup-py ns/leaderElection:leaderElection
, it will only build a target that leaves off the
name
field.
ns/leaderElection:cassandra
will just build that one.
ns/leaderElection:
is a glob to build everything in the directory. (https://www.pantsbuild.org/docs/goals#file-arguments-vs-target-arguments)
b

billowy-motherboard-58443

09/29/2020, 6:50 PM
ah, cool
Ok, here's a short file with the understanding of how it would be put together end-to-end
Pants-TODO
please point out any misunderstandings 🙂
and :thank you:
h

hundreds-father-404

09/29/2020, 7:02 PM
Yep, that looks right! Small suggestion that the target name
cassandra_lib
and
zookeeper_lib
might be more clear what they are (and shorter)
b

billowy-motherboard-58443

09/29/2020, 7:11 PM
kewl
do those python_library(name=...) have to be globally unique or..?
h

hundreds-father-404

09/29/2020, 7:13 PM
The
name
only needs to be unique to the
BUILD
file. Because an
address
== the path to the BUILD file + the
name
, it’s guaranteed that the final address will be unique https://www.pantsbuild.org/docs/targets#target-addresses
👖 1
b

billowy-motherboard-58443

09/29/2020, 7:22 PM
👍
3 Views