Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion advanced/advanced_numpy/examples/mandel-answer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

cdef void mandel_single_point(double complex *z_in,
double complex *c_in,
double complex *z_out) nogil:
double complex *z_out) noexcept nogil:
#
# The Mandelbrot iteration
#
Expand Down
36 changes: 13 additions & 23 deletions advanced/advanced_numpy/examples/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,18 @@
C sources.
"""

import os
import sys
from os.path import join
from distutils.sysconfig import get_python_inc
from setuptools import setup, Extension
from Cython.Build import cythonize
import numpy
from numpy.distutils.misc_util import get_numpy_include_dirs


def configuration(parent_package="", top_path=None):
from numpy.distutils.misc_util import Configuration

for filename in ["mandel.so"]:
# make sure we don't have stale files lying around
if os.path.isfile(filename):
os.unlink(filename)

config = Configuration("", parent_package, top_path)
config.add_extension("mandel", sources=["mandel.c"])
return config


if __name__ == "__main__":
from numpy.distutils.core import setup

setup(**configuration(top_path="").todict())
extensions = [
Extension(
"mandel",
sources=["mandel.pyx"],
include_dirs=[numpy.get_include()]
)
]

setup(
ext_modules=cythonize(extensions)
)
2 changes: 1 addition & 1 deletion advanced/advanced_numpy/examples/setup_myobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

"""

from distutils.core import setup, Extension
from setuptools import setup, Extension

setup(
name="myobject",
Expand Down
15 changes: 11 additions & 4 deletions advanced/interfacing_with_c/cython/setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from distutils.core import setup, Extension
from Cython.Distutils import build_ext
from setuptools import setup, Extension
from Cython.Build import cythonize


extensions = [
Extension(
"cos_module",
sources=["cos_module.pyx"]
)
]

setup(
cmdclass={"build_ext": build_ext},
ext_modules=[Extension("cos_module", ["cos_module.pyx"])],
ext_modules=cythonize(extensions)
)
22 changes: 12 additions & 10 deletions advanced/interfacing_with_c/cython_numpy/setup.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from distutils.core import setup, Extension
from setuptools import setup, Extension
from Cython.Build import cythonize
import numpy
from Cython.Distutils import build_ext


extensions = [
Extension(
"cos_doubles",
sources=["_cos_doubles.pyx", "cos_doubles.c"],
include_dirs=[numpy.get_include()]
)
]

setup(
cmdclass={"build_ext": build_ext},
ext_modules=[
Extension(
"cos_doubles",
sources=["_cos_doubles.pyx", "cos_doubles.c"],
include_dirs=[numpy.get_include()],
)
],
ext_modules=cythonize(extensions)
)
15 changes: 11 additions & 4 deletions advanced/interfacing_with_c/cython_simple/setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from distutils.core import setup, Extension
from Cython.Distutils import build_ext
from setuptools import setup, Extension
from Cython.Build import cythonize


extensions = [
Extension(
"cos_module",
sources=["cos_module.pyx"]
)
]

setup(
cmdclass={"build_ext": build_ext},
ext_modules=[Extension("cos_module", ["cos_module.pyx"])],
ext_modules=cythonize(extensions)
)
20 changes: 10 additions & 10 deletions advanced/interfacing_with_c/interfacing_with_c.rst
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ return types into place and for the module initialisation. Although some of
this is amortised, as the extension grows, the boilerplate required for each
function(s) remains.

The standard python build system ``distutils`` supports compiling C-extensions
from a ``setup.py``, which is rather convenient:
The standard python build system, ``setuptools``, supports compiling
C-extensions via a ``setup.py`` file:

.. literalinclude:: python_c_api/setup.py
:language: python

This can be compiled:
The setup file is called as follows:

.. sourcecode:: console

Expand Down Expand Up @@ -227,7 +227,7 @@ returns a resulting new array.
.. literalinclude:: numpy_c_api/cos_module_np.c
:language: c

To compile this we can use distutils again. However we need to be sure to
To compile this we can use ``setuptools`` again. However we need to be sure to
include the NumPy headers by using :func:`numpy.get_include`.

.. literalinclude:: numpy_c_api/setup.py
Expand Down Expand Up @@ -361,7 +361,7 @@ The function implementation resides in the following C source file:
.. literalinclude:: ctypes_numpy/cos_doubles.c
:language: c

And since the library is pure C, we can't use ``distutils`` to compile it, but
And since the library is pure C, we can't use ``setuptools`` to compile it, but
must use a combination of ``make`` and ``gcc``:

.. literalinclude:: ctypes_numpy/makefile
Expand Down Expand Up @@ -464,7 +464,7 @@ Generating the compiled wrappers is a two stage process:
module.

#. Compile the ``cos_module_wrap.c`` into the ``_cos_module.so``. Luckily,
``distutils`` knows how to handle SWIG interface files, so that our
``setuptools`` knows how to handle SWIG interface files, so that our
``setup.py`` is simply:

.. literalinclude:: swig/setup.py
Expand Down Expand Up @@ -576,7 +576,7 @@ file:
header, There is nothing there that we wish to expose to Python since we
expose the functionality through ``cos_doubles_func``.

And, as before we can use distutils to wrap this:
And, as before we can use ``setuptools`` to wrap this:

.. literalinclude:: swig_numpy/setup.py
:language: python
Expand Down Expand Up @@ -670,8 +670,8 @@ The main Cython code for our ``cos_module`` is contained in the file
Note the additional keywords such as ``cdef`` and ``extern``. Also the
``cos_func`` is then pure Python.

Again we can use the standard ``distutils`` module, but this time we need some
additional pieces from the ``Cython.Distutils``:
Again we can use the standard ``setuptools`` module, but this time we need some
additional pieces from ``Cython.Build``:

.. literalinclude:: cython/setup.py

Expand Down Expand Up @@ -774,7 +774,7 @@ This is wrapped as ``cos_doubles_func`` using the following Cython code:
.. literalinclude:: cython_numpy/_cos_doubles.pyx
:language: cython

And can be compiled using ``distutils``:
And can be compiled using ``setuptools``:

.. literalinclude:: cython_numpy/setup.py
:language: python
Expand Down
7 changes: 5 additions & 2 deletions advanced/interfacing_with_c/numpy_c_api/setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from distutils.core import setup, Extension
from setuptools import setup, Extension
import numpy


# define the extension module
cos_module_np = Extension(
"cos_module_np", sources=["cos_module_np.c"], include_dirs=[numpy.get_include()]
"cos_module_np",
sources=["cos_module_np.c"],
include_dirs=[numpy.get_include()]
)

# run the setup
Expand Down
12 changes: 9 additions & 3 deletions advanced/interfacing_with_c/python_c_api/setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from distutils.core import setup, Extension
from setuptools import setup, Extension


# define the extension module
cos_module = Extension("cos_module", sources=["cos_module.c"])
cos_module = Extension(
"cos_module",
sources=["cos_module.c"]
)

# run the setup
setup(ext_modules=[cos_module])
setup(
ext_modules=[cos_module]
)
12 changes: 10 additions & 2 deletions advanced/interfacing_with_c/swig/setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
from distutils.core import setup, Extension
from setuptools import setup, Extension

setup(ext_modules=[Extension("_cos_module", sources=["cos_module.c", "cos_module.i"])])

setup(
ext_modules=[
Extension(
"_cos_module",
sources=["cos_module.c", "cos_module.i"]
)
]
)
Loading