I try to implement the answer https://stackoverflow.com/a/57480599/7482208, but I am stuck on cimporting one package from another.
The code is here: https://github.com/iamishalkin/setuptools_cython_question
What I want is to have one independent package wrap from wrapper folder such that you can use it without cust package.
And I also want to be able to create custom functions by inheriting FuncWrapper class from wrap.
What I do:
- Firstly I run
python setup.py bdist_wheelinwrapperfolder (this is what I am doing wrong, I suppose, as it gives me only binary file) - Next
pip instal dist/(some_name).whl - Next I add
import wrapandinclude_dirs=wrap.get_include()tocustom/setup.pylike it is done innumpy - I run
python setup.py bdist_wheelincustomfolder and this fails, on the first step no files except binary one were created
So the question is: how to add .pxd files to the final package.
I also tried sdist which does not compile cython code but just copies it.
As I said in a comment, the Cython documentation recommends putting .pxd files in
package_datato install them. This necessitates a slightly different structure:setup.py then creates a "package" called wrapper (this is modified from your version so it's possible it could be simplied further):
Note that I've changed the name of the extension to "wrapper.wrap" to ensure that it's installed as part of the package. The
package_datais then able to recognised .pxd files as part ofwrapperthat you want to install. This doesn't work unless you put it in a "package".You then install it. I just installed it with
python3 setup.py installbut I'm sure going through a wheel does largely the same thing.For another module to use you file it's very simple:
The setup.py for that other module need have nothing special - you definitely don't need anything like
include_dirs=wrap.get_include().If you want to have an interface where you don't need submodules so can just do
then just use an
__init__.pycontaining:and an
__init__.pxdcontaining:I'm sure there are other ways of doing this - I've only really used setuptools for compiling Cython stuff and never really worried about distributing too much so am not an expert - but this looks to be the standard approach.