I came across this `python_binary` target from pan...
# general
r
I came across this
python_binary
target from pant v1. Is this same as
python_sources
or
python_distribution
? I actually find this documentation more elaborate in terms of python support than v2. https://v1.pantsbuild.org/python_readme.html
c
I would guess that it is
pex_binary
in v2.
r
Ah yes! Actually I wanted know what's the subtitute for
python_library
in v2?
c
That is
python_sources
Eh, wait..
coming from pants v1? Must double check in that case, that’s before my time 🙂
r
yeah doesn't seem so according to the description
python_library
BUILD targets make Python code "import-able"
Maybe it's not supported.
c
But yes, I think it still applies. So pants v1 has
python_library
which we also had until recently in v2, where it was renamed to
python_sources
.
r
How would you import a
python_sources
generated target?
c
If you have
src/pkg/mod/source.py
Then in
src/pkg/mod/BUILD
a
python_sources
, you can then import your
source.py
as
import pkg.mod.source
from other modules.
1
(also with proper
__init__.py
files along the way.. and source roots properly configured.)
r
Yes it works under the hood as long as all the things you have mentioned is set-up properly.
👍 1
h
Yes,
python_sources
is what used to be called
python_library
You should be able to just import things the usual way, as long as source roots are set up correctly
you shouldn't need explicit dependencies in BUILD files in the usual case (unlike v1)
And re
__init__.py
, those are necessary only where Python itself deems them necessary
Which is "usually"... Technically in Python 3 you can omit them in some cases, and then you get an implicit namespace package, but in practice that causes all sorts of issues
Can you give more details on what you find useful in the v1 docs, we'd definitely want to make sure v2 docs include everything useful! It's a documentation bug if not...
r
I just felt things were more visible in terms of what's going under the hood in V1. I guess it's intentional in V2 to bit conceal the internals. Also I see lot of glob patterns being mentioned in V1 than it's in V2. V2 targets generally reference single files or handful.