Hi Geert,
On Wed, Aug 21, 2013 at 5:37 PM, Geert Jansen
<
geert....@ravellosystems.com> wrote:
> I'm following the docs on how to distribute a module that uses CFFI. This
> has the effect that the setup script becomes dependent on cffi. Is there a
> way in which the cffi package can be automatically installed by pip when
> installing an sdist from PyPI, *before* pip attempts to run the setup
> script?
>
> I did a hack where I manually run easy_install if cffi is not available. But
> it's not very pretty. See:
Ah, good question. Actually, this is something we missed so far. I
don't have a good solution. I suppose that doing it properly would
require some refactorings of how setup.py is usually written, but even
so it's not clear how to do it.
As an "appetizer", here is how it would most likely look like in the
future CFFI 1.0: you'd write a separate module that is *not* imported
by your program:
ffi = FFI()
ffi.cdef("...lots of lines...")
ffi.make_library("foo", "...lines like in ffi.verify...")
And you would run this explicitly in order to make or re-make the
"foo.so" module. Then your program would simply say:
ffi = FFI("foo")
Which avoids all issues like computing checksums to know if it looks
like we need to rebuild something, as well as needing to re-parse the
cdef, which can take a significant time at import.
In the model above, setup.py would only reference the separate module
by *name*. When you run setup.py it works even if cffi is not
installed yet, as long as it installs it before trying to import the
separate module. Again, however, how to do it exactly is not very
clear so far.
A bientôt,
Armin.