-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.py
98 lines (77 loc) · 2.98 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import re
import numpy
from setuptools import setup
from numpy.distutils.misc_util import Configuration
# Set this to True to enable building extensions using Cython. Set it to False·
# to build extensions from the C file (that was previously generated using·
# Cython). Set it to 'auto' to build with Cython if available, otherwise from·
# the C file.
USE_CYTHON = 'auto'
# If we are in a release, we never use Cython directly
IS_RELEASE = os.path.exists('PKG-INFO')
if IS_RELEASE:
USE_CYTHON = False
# If we do want to use Cython, we double check if it is available
if USE_CYTHON:
try:
from Cython.Build import cythonize
except ImportError:
if USE_CYTHON == 'auto':
USE_CYTHON = False
else:
raise
def configuration():
# This is the numpy Configuration class
config = Configuration('numpy_c_skeleton', '', None)
# Wrapper code in Cython uses the .pyx extension if we want to USE_CYTHON,
# otherwise it ends in .c.
wrapper_ext = '*.pyx' if USE_CYTHON else '*.c'
# Sources include the C/Cython code from the wrapper and the source code of
# the C library
sources = [
os.path.join('numpy_c_skeleton', 'cython_wrapper', wrapper_ext),
os.path.join('src', 'c_package', 'src', '*.c'),
]
# Dependencies are the header files of the C library and any potential
# helper code between the library and the Cython code
depends = [
os.path.join('src', 'c_package', 'include', '*.h'),
os.path.join('src', 'c_package', 'c_package_helper.c')
]
# Register the extension
config.add_extension('cython_wrapper.wrapper',
sources=sources,
include_dirs=[
os.path.join('src', 'c_package'),
os.path.join('src', 'c_package', 'include'),
numpy.get_include(),
],
depends=depends)
# Cythonize if necessary
if USE_CYTHON:
config.ext_modules = cythonize(config.ext_modules)
return config
def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()
if __name__ == '__main__':
# Pull the version from the package __init__.py
version = re.search("__version__ = '([^']+)'",
open('numpy_c_skeleton/__init__.py').read()).group(1)
# load the configuration
attr = configuration().todict()
# Add the other setup attributes
attr['description'] = 'Python package skeleton for numpy C extension'
attr['long_description'] = read('README.rst')
attr['packages'] = ['numpy_c_skeleton']
attr['version'] = version
attr['author'] = "G.J.J. van den Burg"
attr['author_email'] = "gertjanvandenburg@gmail.com"
attr['license'] = 'GPL v2'
attr['install_requires'] = ['numpy']
attr['zip_safe'] = True
attr['url'] = 'https://github.com/GjjvdBurg/NumPy_C_Extension'
# Finally, run the setup command
setup(**attr)