Skip to content

Commit 6305f40

Browse files
Merge pull request #769 from stefanv/rm-distutils
Remove distutils
2 parents a1da5b5 + 574caa0 commit 6305f40

File tree

13 files changed

+1668
-288
lines changed

13 files changed

+1668
-288
lines changed

.git-blame-ignore-revs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ bb473f6ff4a23e4fd5205eacdef713db15decadf
77
d6b447cab8c40aa47dc675a0f4349ae254e8b3ce
88
d8966d848af75751823e825eb76c5bbff58f5c07
99
4902d468c9606836b26b393379df4f49208ea847
10+
1fd0ce6759be32be38bbfab32e83d157a82dfe25

advanced/advanced_numpy/examples/mandel-answer.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
cdef void mandel_single_point(double complex *z_in,
55
double complex *c_in,
6-
double complex *z_out) nogil:
6+
double complex *z_out) noexcept nogil:
77
#
88
# The Mandelbrot iteration
99
#

advanced/advanced_numpy/examples/setup.py

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,12 @@
66
C sources.
77
"""
88

9-
import os
10-
import sys
11-
from os.path import join
12-
from distutils.sysconfig import get_python_inc
9+
from setuptools import setup, Extension
10+
from Cython.Build import cythonize
1311
import numpy
14-
from numpy.distutils.misc_util import get_numpy_include_dirs
1512

13+
extensions = [
14+
Extension("mandel", sources=["mandel.pyx"], include_dirs=[numpy.get_include()])
15+
]
1616

17-
def configuration(parent_package="", top_path=None):
18-
from numpy.distutils.misc_util import Configuration
19-
20-
for filename in ["mandel.so"]:
21-
# make sure we don't have stale files lying around
22-
if os.path.isfile(filename):
23-
os.unlink(filename)
24-
25-
config = Configuration("", parent_package, top_path)
26-
config.add_extension("mandel", sources=["mandel.c"])
27-
return config
28-
29-
30-
if __name__ == "__main__":
31-
from numpy.distutils.core import setup
32-
33-
setup(**configuration(top_path="").todict())
17+
setup(ext_modules=cythonize(extensions))

advanced/advanced_numpy/examples/setup_myobject.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
"""
88

9-
from distutils.core import setup, Extension
9+
from setuptools import setup, Extension
1010

1111
setup(
1212
name="myobject",
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from distutils.core import setup, Extension
2-
from Cython.Distutils import build_ext
1+
from setuptools import setup, Extension
2+
from Cython.Build import cythonize
33

4-
setup(
5-
cmdclass={"build_ext": build_ext},
6-
ext_modules=[Extension("cos_module", ["cos_module.pyx"])],
7-
)
4+
5+
extensions = [Extension("cos_module", sources=["cos_module.pyx"])]
6+
7+
setup(ext_modules=cythonize(extensions))
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
from distutils.core import setup, Extension
1+
from setuptools import setup, Extension
2+
from Cython.Build import cythonize
23
import numpy
3-
from Cython.Distutils import build_ext
44

5-
setup(
6-
cmdclass={"build_ext": build_ext},
7-
ext_modules=[
8-
Extension(
9-
"cos_doubles",
10-
sources=["_cos_doubles.pyx", "cos_doubles.c"],
11-
include_dirs=[numpy.get_include()],
12-
)
13-
],
14-
)
5+
6+
extensions = [
7+
Extension(
8+
"cos_doubles",
9+
sources=["_cos_doubles.pyx", "cos_doubles.c"],
10+
include_dirs=[numpy.get_include()],
11+
)
12+
]
13+
14+
setup(ext_modules=cythonize(extensions))
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from distutils.core import setup, Extension
2-
from Cython.Distutils import build_ext
1+
from setuptools import setup, Extension
2+
from Cython.Build import cythonize
33

4-
setup(
5-
cmdclass={"build_ext": build_ext},
6-
ext_modules=[Extension("cos_module", ["cos_module.pyx"])],
7-
)
4+
5+
extensions = [Extension("cos_module", sources=["cos_module.pyx"])]
6+
7+
setup(ext_modules=cythonize(extensions))

advanced/interfacing_with_c/interfacing_with_c.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,13 @@ return types into place and for the module initialisation. Although some of
131131
this is amortised, as the extension grows, the boilerplate required for each
132132
function(s) remains.
133133

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

137137
.. literalinclude:: python_c_api/setup.py
138138
:language: python
139139

140-
This can be compiled:
140+
The setup file is called as follows:
141141

142142
.. sourcecode:: console
143143

@@ -227,7 +227,7 @@ returns a resulting new array.
227227
.. literalinclude:: numpy_c_api/cos_module_np.c
228228
:language: c
229229

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

233233
.. literalinclude:: numpy_c_api/setup.py
@@ -361,7 +361,7 @@ The function implementation resides in the following C source file:
361361
.. literalinclude:: ctypes_numpy/cos_doubles.c
362362
:language: c
363363

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

367367
.. literalinclude:: ctypes_numpy/makefile
@@ -464,7 +464,7 @@ Generating the compiled wrappers is a two stage process:
464464
module.
465465

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

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

579-
And, as before we can use distutils to wrap this:
579+
And, as before we can use ``setuptools`` to wrap this:
580580

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

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

676676
.. literalinclude:: cython/setup.py
677677

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

777-
And can be compiled using ``distutils``:
777+
And can be compiled using ``setuptools``:
778778

779779
.. literalinclude:: cython_numpy/setup.py
780780
:language: python

advanced/interfacing_with_c/numpy_c_api/setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from distutils.core import setup, Extension
1+
from setuptools import setup, Extension
22
import numpy
33

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

advanced/interfacing_with_c/python_c_api/setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from distutils.core import setup, Extension
1+
from setuptools import setup, Extension
2+
23

34
# define the extension module
45
cos_module = Extension("cos_module", sources=["cos_module.c"])
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
from distutils.core import setup, Extension
1+
from setuptools import setup, Extension
2+
23

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

0 commit comments

Comments
 (0)