Hello, I've been trying to `cythonize` some files ...
# general
p
Hello, I've been trying to
cythonize
some files using Pants. These are my attempts so far using a
python_distribution
target: • Dist has only
dependencies
on the source package, uses a generated
setup.py
and
provides=python_artifact
, I can build a package (without cython ofc) • Adding a
pyproject.toml
dependency (requiring
["setuptools", "wheel", "Cython"]
does create a target, but it doesn't
cythonize
files • Adding a minimal
setup.py
with
_ext_modules_=cythonize([Extension("*", ["*.pyx"])])
produced this error:
ValueError: '*.pyx' doesn't match any files
Has anyone dealt with this before? The
.pyx
file lives at the same level as the
setup.py
, I tried globbing with directories too (
src/test/test.pyx
) without success. I can provide more details if required, this setup is as minimal as I can get it (even though it's part of a bigger project)
👍 1
c
You’ll need to make sure that your .pyx files are included in the dist by depending on a target that references them with a sources field. try with a
files
target perhaps:
files(name="pyx-sources", sources=["*.pyx"])
and add a dependency on that from your
python_distribution
. Running with
--no-process-cleanup
and inspecting the sandbox packaging your dist may give you valuable insights as you can inspect what goes into the sandbox, and the command invoked to package it.
🙌 2
p
ok it seems to be running now! I'm using
resources
instead of
files
🎉 1
👍 2
h
@plain-fireman-49959 would you mind opening a ticket to request "proper" cython support? At the very least it would be easy to add a
cython_sources
target to glob over *.pyx files, and it might be possible for the generated setup.py to add the
ext_modules=
automatically.
👍 3
Adding the steps you took to get it working to that ticket would be really informative and helpful
So it doesn't get lost in the ephemerality of Slack...
p
I'm kind of documenting this internally with my org, if you'd like me to open an issue I'll do so! I still have problems
pants run
ing another with a cython distribution as a dependency, I'll sort it out soon though! I'll try to open an issue tomorrow or next week
h
Thanks! It'll be helpful to gather cython use-cases so we can improve support. We prefer to have things work more-or-less out of the box if we can!
💯 1
p
I'm trying to setup a minimal example/repo where I can test stuff out. I can build wheels from
.pyx
files, but I'd like to expand it to support more feature (see README). https://github.com/houtenjack/pants-cython-minimal-example An issue in the pants repo will follow soon!
👍 2
w
@happy-kitchen-89482 I added a link with some context to the
mypyc
plugin I've been sorta working on as well. I think it would be handy to be able to auto-generate full
setup.py
for plugins that need to do more manipulation than just kwargs I do like the idea of having a custom target field that will automatically add it to the
setup.py
though, but from the side of creating sample plugins (like I like to do), I think w're missing a bit of functionality https://github.com/pantsbuild/pants/issues/14752#issuecomment-1064089880