forked from abelfunctions/abelfunctions
/
setup.py
178 lines (154 loc) · 6.12 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/env python
"""Setup script for abelfunctions
To install Abelfunctions for your user account run:
$ sage setup.py install --user
To build Abelfunctions in-place (used in running the test suite) run:
$ sage setup.py build_ext --inplace
To install in a custom directory <dir> use:
$ sage setup.py install --prefix=<dir>
Developers: to clean the directory of any extraneous files, such as compiled
Python .pyc and Cython .o/.so output and run:
$ sage setup.py clean
"""
import os
import sys
import shutil
import unittest
from distutils.core import setup, Command
from distutils.extension import Extension
from Cython.Build import cythonize
from numpy.distutils.misc_util import get_numpy_include_dirs
# raise error if the user is not using Sage to compile
try:
from sage.env import sage_include_directories
SAGE_ROOT = os.environ['SAGE_ROOT']
except (ImportError, KeyError):
raise EnvironmentError('abelfunctions must be built using Sage:\n\n'
'\t$ sage setup.py <args> <kwds>\n')
# list of Abelfunctions extension modules. most modules need to be compiled
# against the Sage and Numpy (included with Sage) libraries. The necessary
# include_dirs are provided after the module list.
#
ext_modules = [
Extension('abelfunctions.complex_path',
sources=[
os.path.join('abelfunctions',
'complex_path.pyx')]
),
Extension('abelfunctions.riemann_surface_path',
sources=[
os.path.join('abelfunctions',
'riemann_surface_path.pyx')]
),
Extension('abelfunctions.puiseux_series_ring_element',
sources=[
os.path.join('abelfunctions',
'puiseux_series_ring_element.pyx')]
),
Extension('abelfunctions.riemann_theta.radius',
sources=[os.path.join('abelfunctions','riemann_theta',
'lll_reduce.c'),
os.path.join('abelfunctions','riemann_theta',
'radius.pyx')]
),
Extension('abelfunctions.riemann_theta.integer_points',
sources=[os.path.join('abelfunctions','riemann_theta',
'integer_points.pyx')]
),
Extension('abelfunctions.riemann_theta.riemann_theta',
sources=[os.path.join('abelfunctions','riemann_theta',
'finite_sum.c'),
os.path.join('abelfunctions','riemann_theta',
'riemann_theta.pyx')]
),
]
# parameters for all extension modules:
#
# * most modules depend on Sage and Numpy. Provide include directories.
# * disable warnings in gcc step
INCLUDES = sage_include_directories()
INCLUDES_NUMPY = get_numpy_include_dirs()
for mod in ext_modules:
mod.include_dirs.extend(INCLUDES)
mod.include_dirs.extend(INCLUDES_NUMPY)
mod.extra_compile_args.append('-w')
mod.extra_compile_args.append('-std=c99')
packages = [
'abelfunctions',
'abelfunctions.riemann_theta',
'abelfunctions.utilities'
]
class clean(Command):
"""Cleans files so you should get the same copy as in git."""
description = 'remove build files'
user_options = [('all', 'a', 'the same')]
def initialize_options(self):
self.all = None
def finalize_options(self):
pass
def run(self):
# delete all files ending with certain extensions
# currently: '.pyc', '~'
dir_setup = os.path.dirname(os.path.realpath(__file__))
curr_dir = os.getcwd()
for root, dirs, files in os.walk(dir_setup):
for file in files:
file = os.path.join(root, file)
if file.endswith('.pyc') and os.path.isfile(file):
print 'deleting %s...'%file
os.remove(file)
if file.endswith('~') and os.path.isfile(file):
print 'deleting %s...'%file
os.remove(file)
os.chdir(dir_setup)
# explicity remove files and directories from 'blacklist'
blacklist = ['build', 'dist', 'doc/_build']
for file in blacklist:
if os.path.isfile(file):
print 'deleting %s...'%file
os.remove(file)
elif os.path.isdir(file):
print 'deleting %s...'%file
shutil.rmtree(file)
os.chdir(dir_setup)
# delete temporary cython .c and .cpp files. be careful to only delete
# the .c and .cpp files corresponding to .pyx files.
ext_sources = [f for ext in ext_modules for f in ext.sources]
for file in ext_sources:
file = os.path.join(dir_setup, file)
if file.endswith('.pyx') and os.path.isfile(file):
(root, ext) = os.path.splitext(file)
file_c = root + '.c'
if os.path.isfile(file_c):
print 'deleting %s...'%file
os.remove(file_c)
file_cpp = root + '.cpp'
if os.path.isfile(file_cpp):
print 'deleting %s...'%file
os.remove(file_cpp)
os.chdir(dir_setup)
# delete cython .so modules
ext_module_names = [ext.name for ext in ext_modules]
for mod in ext_module_names:
file = mod.replace('.', os.path.sep) + '.so'
file = os.path.join(dir_setup, file)
if os.path.isfile(file):
print 'deleting %s...'%file
os.remove(file)
os.chdir(curr_dir)
# configure setup
exec(open('abelfunctions/version.py').read())
setup(
name = 'abelfunctions',
version = __version__,
description = 'A library for computing with Abelian functions, Riemann '
'surfaces, and algebraic curves.',
author = 'Chris Swierczewski',
author_email = 'cswiercz@gmail.com',
url = 'https://github.com/cswiercz/abelfunctions',
license = 'MIT',
packages = packages,
ext_modules = cythonize(ext_modules),
platforms = ['all'],
cmdclass = {'clean':clean}
)