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

early-toothbrush-63898

01/28/2021, 5:18 PM
Hi. I’m a pantsbuild newbie (quite experienced with normal pants 👖 though 😉 ). There were some teasers about cython in the documentation, but I couldn’t find any actual plugin code. Our current monorepo uses both Cython and f2py. Are there any examples of the cython plugin and are there any plans for broader support for C/fortran extensions?
h

hundreds-father-404

01/28/2021, 5:38 PM
Hey Noah, welcome! 😂 glad to have you Indeed, a user wrote a Cython plugin near the end of last year. It's not upstreamed, but I think they shared it in #plugins. Let me try finding it How are y'all using Cython? I've seen a couple different ways to invoke it We would definitely be interested in better first-class support, and we're happy to help you with writing a plugin (whether you upstream it or not)
e

early-toothbrush-63898

01/28/2021, 5:46 PM
Thanks. We use cython in a similar way to the setup.py example in the docs. For fortran extension modules we have something like this
Copy code
from numpy.distutils.core import Extension, setup
setup(  
    packages=find_packages(),

    ext_modules=[Extension(name="package.fortran", sources=glob("src/*.f90"))],
)
f

flat-zoo-31952

01/28/2021, 5:53 PM
i would hazard a guess that using the command line -based compilation is the best way to go, since that seems simpler than trying to integrate with setuptools nevermind, you would need to manually manage C compilation after that
h

hundreds-father-404

01/28/2021, 5:54 PM
a similar way to the setup.py example in the docs
Cool, that is what the other user Noah Pederson was using. See https://pantsbuild.slack.com/archives/C01CQHVDMMW/p1602024437005400 and the threads a little after for convos related to Noah's plugin. It looks like this is the latest gist we have https://gist.github.com/chiefnoah/5ef8bf37cbc724a3f2e7216cf858220a That first thread explains a bit how you will be using the codegen plugin hook so that Pants knows how to convert your
.pyx
files into something like a
.so
file Also refer to the plugin docs, starting with https://www.pantsbuild.org/docs/plugins-overview A couple people have commented that the hardest part of writing a plugin is figuring out what the heck you want it to do - it's really helpful if you know what commands you'd run without Pants to get this done; Pants is more or less an orchestrator for other tools.
It's really helpful if you know what commands you'd run without Pants to get this done; Pants is more or less an orchestrator for other tools.
We're happy to talk through this, and any later parts. Feel free to start a thread in #plugins I'd probably recommend this workflow: 1. Confirm if you want to stick with setup.py vs. using the CLI. Either are valid. Josh is probably right that CLI may be simpler, but it would mean rewriting your current workflow + Noah's example not being as helpful, so maybe not. 2. Write down how you do this without Pants, including what commands you run 3. check out the basics of writing a plugin. Get an example working with the Target API, which is simpler than the Rules API. This will ensure you have things loading correctly 4. read over the Rules API docs, you don't need to fully understand everything at this point 5. follow that guide + Noah's example to use the codegen hook
e

early-toothbrush-63898

01/28/2021, 5:58 PM
Thanks for sharing Eric. That does look pretty straightforward after perusing the plugin developer docs last night (great job on these btw). Josh, yah that was my concern, codegen to C but then what…Plugging into setup.py seems a little easier.
❤️ 1