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

echoing-farmer-15630

09/16/2021, 10:20 AM
OK, I feel silly for asking because I'm sure it's been solved, but I searched and didn't see... how do you do a python library with eg C extensions? Or worse, cuda? (got some internal libraries which do this, and while we could package them and then use them as third-party extensions, it's not elegant). Do I need to write a plugin of some sort?
c

curved-television-6568

09/16/2021, 10:26 AM
Not silly at all. Native extensions are mentioned in the docs here: https://www.pantsbuild.org/v2.8/docs/python-distributions#using-an-existing-setuppy
Seems like providing your own setup.py file is the way to go, in those cases…
e

echoing-farmer-15630

09/16/2021, 10:27 AM
Ah! I kept seeing how plugins can modify setup.py, but this should do the trick. Thanks!
👍 1
Ah, because I kept looking for
python_library
support, but one presumes that if you build a
python_distribution
pants will sort out the dependencies if you need it somewhere else (I hope!). But that should indeed do the trick; thanks.
h

happy-kitchen-89482

09/16/2021, 1:48 PM
As @curved-television-6568 mentioned, you write your own
setup.py
to build the native extension, and wrap it in a
python_distribution
. As of today, you'd then have to publish it and consume it as a 3rdparty dep. However this PR https://github.com/pantsbuild/pants/pull/12573 will allow
test
,
run
and
repl
to consume it directly from the repo. I hope to land that in the next day or two.
So the situation right now is meh, in the next dev release it will be much better.
🙌 1
How are you deploying the code that depends on the native extension? Wheels? Pex?
5 Views