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

refined-addition-53644

12/09/2021, 6:25 PM
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

curved-television-6568

12/09/2021, 6:27 PM
I would guess that it is
pex_binary
in v2.
r

refined-addition-53644

12/09/2021, 6:29 PM
Ah yes! Actually I wanted know what's the subtitute for
python_library
in v2?
c

curved-television-6568

12/09/2021, 6:30 PM
That is
python_sources
Eh, wait..
coming from pants v1? Must double check in that case, that’s before my time 🙂
r

refined-addition-53644

12/09/2021, 6:31 PM
yeah doesn't seem so according to the description
python_library
BUILD targets make Python code "import-able"
Maybe it's not supported.
c

curved-television-6568

12/09/2021, 6:32 PM
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

refined-addition-53644

12/09/2021, 6:32 PM
How would you import a
python_sources
generated target?
c

curved-television-6568

12/09/2021, 6:33 PM
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

refined-addition-53644

12/09/2021, 6:36 PM
Yes it works under the hood as long as all the things you have mentioned is set-up properly.
👍 1
h

happy-kitchen-89482

12/09/2021, 8:43 PM
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

refined-addition-53644

12/09/2021, 9:15 PM
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.
4 Views