-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsetup.py
226 lines (189 loc) · 6.64 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/usr/bin/env python
#
# $Id: setup.py,v 1.34 2010/04/09 21:28:15 mrnolta Exp $
#
# Copyright (C) 2001-10 :
#
# Berthold Hollmann <[email protected]>
# Mike Nolta <[email protected]>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
#
#
# distutils setup file for biggles originally contributed
# by Berthold Hollmann.
#
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
import os
from subprocess import Popen
import glob
import shutil
class build_ext_subclass(build_ext):
plotutils_dir = 'plotutils'
def initialize_options(self):
build_ext.initialize_options(self)
def finalize_options(self):
build_ext.finalize_options(self)
self.plotutils_build_dir = os.path.join(
self.build_temp,
self.plotutils_dir,
)
# self.plot_h_dir = os.path.join(self.plotutils_dir, 'include')
# self.libplot_dir = os.path.join(
# self.plotutils_dir, 'libplot', '.libs',
# )
self.plot_h_dir = os.path.join(
self.plotutils_build_dir, 'include')
self.libplot_dir = os.path.join(
self.plotutils_build_dir, 'libplot', '.libs',
)
self.include_dirs.insert(0, self.plot_h_dir)
def run(self):
# For extensions that require 'numpy' in their include dirs,
# replace 'numpy' with the actual paths
import numpy
np_include = numpy.get_include()
for extension in self.extensions:
if 'numpy' in extension.include_dirs:
idx = extension.include_dirs.index('numpy')
extension.include_dirs.insert(idx, np_include)
extension.include_dirs.remove('numpy')
build_ext.run(self)
def build_extensions(self):
# Use the compiler for building python to build plotutils
# for maximized compatibility.
CCold = self.compiler.compiler
CC = []
for val in CCold:
"""
if val == '-O3':
print("replacing '-O3' with '-O2' to address "
"gcc bug")
val = '-O2'
"""
if val == 'ccache':
print("removing ccache from the compiler options")
continue
CC.append(val)
self.configure_plotutils(
CC=CC,
ARCHIVE=self.compiler.archiver,
RANLIB=self.compiler.ranlib,
)
libs = [
# "plot",
"Xaw", "Xmu", "Xt", "SM", "ICE", "Xext", "X11",
"png", "z", "m",
]
for lib in libs:
self.compiler.add_library(lib)
self.compile_plotutils()
link_objects = glob.glob(
os.path.join(self.libplot_dir, '*.a'),
)
self.compiler.set_link_objects(link_objects)
# Ultimate hack: append the .a files to the dependency list
# so they will be properly rebuild if source updated.
for ext in self.extensions:
ext.depends += link_objects
# call the original build_extensions
build_ext.build_extensions(self)
def configure_plotutils(self, CC=None, ARCHIVE=None, RANLIB=None):
# prepare source code and run configure
def copy_update(dir1, dir2):
f1 = os.listdir(dir1)
for f in f1:
path1 = os.path.join(dir1, f)
path2 = os.path.join(dir2, f)
if os.path.isdir(path1):
if not os.path.exists(path2):
os.makedirs(path2)
copy_update(path1, path2)
else:
if not os.path.exists(path2):
shutil.copy(path1, path2)
else:
stat1 = os.stat(path1)
stat2 = os.stat(path2)
if (stat1.st_mtime > stat2.st_mtime):
shutil.copy(path1, path2)
if not os.path.exists('build'):
os.makedirs('build')
if not os.path.exists(self.plotutils_build_dir):
os.makedirs(self.plotutils_build_dir)
copy_update(self.plotutils_dir, self.plotutils_build_dir)
makefile = os.path.join(self.plotutils_build_dir, 'Makefile')
if os.path.exists(makefile):
# Makefile already there
return
p = Popen(
"sh ./configure --enable-shared=no --with-pic",
shell=True,
cwd=self.plotutils_build_dir,
)
p.wait()
if p.returncode != 0:
raise ValueError("could not configure plotutils")
def compile_plotutils(self):
p = Popen(
"make",
shell=True,
cwd=self.plotutils_build_dir,
)
p.wait()
if p.returncode != 0:
raise ValueError("could not compile plotutils")
fp = open('README.rst', 'r')
long_description = fp.read()
fp.close()
biggles_ext = Extension(
"_biggles",
["biggles/_biggles.c"],
include_dirs=['numpy'],
library_dirs=['/usr/X11/lib'],
)
biggles_libplot_ext = Extension(
"libplot._libplot_pywrap",
["biggles/libplot/_libplot_pywrap.c"],
include_dirs=['numpy'],
library_dirs=['/usr/X11/lib'],
)
ext_modules = [biggles_ext, biggles_libplot_ext]
classifiers = [
"Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: GNU General Public License (GPL)",
"Topic :: Scientific/Engineering :: Astronomy",
"Intended Audience :: Science/Research",
]
setup(
name="biggles",
version="2.0.0",
author="Mike Nolta",
author_email="[email protected]",
url="https://github.com/biggles-plot/biggles",
license="GPL-2",
description="simple, elegant python plotting",
long_description=long_description,
packages=["biggles", "biggles.libplot"],
classifiers=classifiers,
setup_requires=['numpy'],
install_requires=['numpy'],
use_2to3=True,
ext_package="biggles",
ext_modules=ext_modules,
cmdclass={"build_ext": build_ext_subclass}
)