|
1 |
| -# from distutils.command.build_ext import build_ext |
2 |
| -# from distutils.errors import CCompilerError, DistutilsExecError, DistutilsPlatformError |
3 |
| -# from setuptools import Extension |
4 |
| -import numpy as np |
5 |
| - |
6 |
| -# ext_modules = [ |
7 |
| -# Extension(name="pyphysim.c_extensions.misc_c", |
8 |
| -# sources=["pyphysim/util/misc_c.pyx"], |
9 |
| -# include_dirs=[np.get_include()]), |
10 |
| -# ] |
11 |
| - |
12 |
| -# class BuildFailed(Exception): |
13 |
| -# pass |
14 |
| - |
15 |
| -# class ExtBuilder(build_ext): |
16 |
| -# def run(self): |
17 |
| -# try: |
18 |
| -# build_ext.run(self) |
19 |
| -# except (DistutilsPlatformError, FileNotFoundError): |
20 |
| -# raise BuildFailed('File not found. Could not compile C extension.') |
21 |
| - |
22 |
| -# def build_extension(self, ext): |
23 |
| -# try: |
24 |
| -# build_ext.build_extension(self, ext) |
25 |
| -# except (CCompilerError, DistutilsExecError, DistutilsPlatformError, |
26 |
| -# ValueError): |
27 |
| -# raise BuildFailed('Could not compile C extension.') |
28 |
| - |
29 |
| -# def build(setup_kwargs): |
30 |
| -# """ |
31 |
| -# This function is mandatory in order to build the extensions. |
32 |
| -# """ |
33 |
| -# setup_kwargs.update({ |
34 |
| -# "ext_modules": ext_modules, |
35 |
| -# "cmdclass": { |
36 |
| -# "build_ext": ExtBuilder |
37 |
| -# } |
38 |
| -# }) |
39 |
| - |
40 | 1 | from setuptools import Extension
|
41 |
| -from Cython.Build import cythonize |
42 |
| - |
43 |
| -cyfuncs_ext = Extension(name="pyphysim.c_extensions.misc_c", |
44 |
| - sources=["pyphysim/util/misc_c.pyx"], |
45 |
| - include_dirs=[np.get_include()]) |
46 |
| - |
47 |
| -EXTENSIONS = [cyfuncs_ext] |
48 | 2 |
|
49 | 3 |
|
50 | 4 | def build(setup_kwargs):
|
51 |
| - setup_kwargs.update({ |
52 |
| - 'ext_modules': cythonize(EXTENSIONS, language_level=3), |
53 |
| - 'zip_safe': False, |
54 |
| - }) |
| 5 | + try: |
| 6 | + import numpy as np |
| 7 | + from Cython.Build import cythonize |
| 8 | + |
| 9 | + cyfuncs_ext = Extension(name="pyphysim.c_extensions.misc_c", |
| 10 | + sources=["pyphysim/util/misc_c.pyx"], |
| 11 | + include_dirs=[np.get_include()]) |
| 12 | + |
| 13 | + EXTENSIONS = [cyfuncs_ext] |
| 14 | + |
| 15 | + setup_kwargs.update({ |
| 16 | + 'ext_modules': |
| 17 | + cythonize(EXTENSIONS, language_level=3), |
| 18 | + 'zip_safe': |
| 19 | + False, |
| 20 | + }) |
| 21 | + except ModuleNotFoundError: |
| 22 | + import warnings |
| 23 | + warnings.warn( |
| 24 | + "numpy and cython must be installed to compyle cython extensions in pyphysim" |
| 25 | + ) |
0 commit comments