cythonize questions...

41 views
Skip to first unread message

Chris Barker

unread,
Oct 3, 2012, 5:11:58 PM10/3/12
to cython-users
While I'm asking questions...

Folks,

I recently discovered the cythonize command for use in your setup.py.

It looks like it gives some nice functionality, and also I like
putting dependency-like information in the pyx, rather than in the
setup.py. HOwever, a couple questions:

The examples I've seen use hard-coded everything -- is it possible to
make that dynamic?, for instance I need the numpy includes:

np.get_include()

Also -- other includes, libs, etc may be in different places on
different systems -- a lot of setup.py's have code to search for
stuff.

What about different platforms -- there are a number of things we need
to set up differently for Windows vs. *nix -- includes, libs, defines,
etc. -- again, we can switch on that in a setup.py, but how would we
do it with Cythonize?

Thanks,
-Chris





--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris....@noaa.gov

Robert Bradshaw

unread,
Oct 3, 2012, 5:30:16 PM10/3/12
to cython...@googlegroups.com
On Wed, Oct 3, 2012 at 2:11 PM, Chris Barker <chris....@noaa.gov> wrote:
> While I'm asking questions...
>
> Folks,
>
> I recently discovered the cythonize command for use in your setup.py.
>
> It looks like it gives some nice functionality, and also I like
> putting dependency-like information in the pyx, rather than in the
> setup.py. HOwever, a couple questions:
>
> The examples I've seen use hard-coded everything -- is it possible to
> make that dynamic?, for instance I need the numpy includes:
>
> np.get_include()
>
> Also -- other includes, libs, etc may be in different places on
> different systems -- a lot of setup.py's have code to search for
> stuff.

You should be able to do

cythonize(..., aliases={'NUMPY_INCLUDES': np.get_include()})

(untested, and just realized we don't even have a test for this either).

> What about different platforms -- there are a number of things we need
> to set up differently for Windows vs. *nix -- includes, libs, defines,
> etc. -- again, we can switch on that in a setup.py, but how would we
> do it with Cythonize?

cythonize() can take a list of Extension objects, which are used as a
template and overlayed to the information found in the sourcefiles.
You can set the name to "*" and the source to "[glob].pyx". This
allows you to split your logic to where it fits best (if you have
complicated, cross-module logic, perhaps it is better in the setup.py
file).

- Robert
Reply all
Reply to author
Forward
0 new messages