-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
243 lines (205 loc) · 7.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
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#!/usr/bin/env python
patch_work_dir = './build' # TODO - hide global
import os
import sys
import distutils
import glob
#import shutil
from distutils.core import setup, Extension
from distutils.core import Distribution, Command
from distutils.command.build import build
from distutils import log
import numpy
import numpy.distutils.system_info
gistsource = glob.glob('yorick/gist/*.c')
gistsource.pop(gistsource.index('yorick/gist/browser.c'))
gistsource.pop(gistsource.index('yorick/gist/bench.c'))
gistsource.pop(gistsource.index('yorick/gist/cgmin.c'))
unixsource = [
'yorick/play/unix/dir.c',
'yorick/play/unix/files.c',
'yorick/play/unix/fpuset.c',
'yorick/play/unix/handler.c',
'yorick/play/unix/pathnm.c',
#'yorick/play/unix/pmain.c',
'yorick/play/unix/usock.c',
'yorick/play/unix/slinks.c',
'yorick/play/unix/stdinit.c',
'yorick/play/unix/timeu.c',
'yorick/play/unix/timew.c',
'yorick/play/unix/udl.c',
'yorick/play/unix/uevent.c',
'yorick/play/unix/ugetc.c',
'yorick/play/unix/uinbg.c',
'yorick/play/unix/umain.c',
'yorick/play/unix/usernm.c',
'yorick/play/unix/uspawn.c',
]
x11source = glob.glob('yorick/play/x11/*.c')
anysource = glob.glob('yorick/play/any/*.c')
anysource.pop(anysource.index('yorick/play/any/hashtest.c'))
anysource.pop(anysource.index('yorick/play/any/test2d.c'))
anysource.pop(anysource.index('yorick/play/any/mmtest.c'))
anysource.extend(glob.glob('yorick/yorick/*.c'))
anysource.pop(anysource.index('yorick/yorick/fortrn.c'))
anysource.pop(anysource.index('yorick/yorick/codger.c'))
anysource.pop(anysource.index('yorick/yorick/parsre.c'))
anysource.extend(glob.glob('yorick/regexp/*.c'))
anysource.extend(glob.glob('yorick/matrix/*.c'))
anysource.extend(glob.glob('yorick/fft/*.c'))
define_macros=[]
extra_compile_args=[
'-Wno-unused-value',
'-O2',
]
# version
version=open('yorick/play/yversion.h').readline()
version=version.strip().split(' ')[-1]
version=version.strip('"')
# GISTPATH to *.g[sp]
gistdata_path = os.path.join(distutils.sysconfig.get_python_lib(1),'gist/gistdata') # 'gist' is pkg.name
gistdata_path = gistdata_path.replace('\\',r'\\\\')
define_macros.append(('GISTPATH', '\\"%s:~/.gist\\"' % gistdata_path ))
define_macros.append(('PYGIST_VERSION', '\\"%s\\"' % version))
define_macros.append(('STAND_ALONE', None )) # for yorick/play/any/numfmt.c
define_macros.append(('YLAPACK_NOALIAS', None ))
define_macros.append(('YCBLAS_NOALIAS', None ))
gist_data=glob.glob('gistdata/*.g[sp]')
gist_data.extend(glob.glob('yorick/g/*.g[sp]'))
data_files = [(gistdata_path, gist_data),]
x11_info = numpy.distutils.system_info.get_info('x11')
library_dirs = x11_info.get('library_dirs',[])
dirs = [ 'yorick/gist', 'yorick/play', 'yorick/play/unix', 'yorick/regexp', 'yorick/matrix', 'yorick/yorick' ]
include_dirs = [os.path.join(patch_work_dir,x) for x in dirs]
include_dirs.extend(['plugin'])
include_dirs.extend(x11_info.get('include_dirs',[]))
libraries = x11_info.get('libraries',['X11'])
include_dirs.extend([numpy.get_include()])
# sources
sources = unixsource + x11source + anysource + gistsource
sources = [ os.path.join(patch_work_dir,f) for f in sources]
sources.append('plugin/plug-hlevel.c')
sources.append('plugin/gistCmodule.c')
class patch_cmd(Command):
description = 'apply patches prior to build'
#user_options = [('name=', 'n', 'option name abreviated by n'),]
boolean_options = ['xft_patch','zeroborder_patch']
#negative_opt = {'no-patch-bool-flag': 'patch-bool-flag'}
def initialize_options(self):
self.xft_patch = True
self.zeroborder_patch = True
def finalize_options(self):
pass
def run(self):
log.info('preparing patch tree copy')
if not os.path.isdir(patch_work_dir): self.mkpath(patch_work_dir)
patchdir=os.path.join(patch_work_dir,'yorick')
#if os.path.isdir(patchdir): shutil.rmtree(patchdir)
self.mkpath(patchdir)
self.copy_tree('yorick', patchdir)
log.info('applying patches')
if self.xft_patch:
xft_info = numpy.distutils.system_info.get_info('xft')
if xft_info:
global include_dirs, libraries
libraries.extend(xft_info.get('libraries',[]))
include_dirs.extend(xft_info.get('include_dirs',[]))
os.system('cd %s && patch -N -p1 < ../../patch/xft.patch' % patchdir)
for ext in self.distribution.ext_modules:
ext.define_macros.append(('HAVE_XFT', None))
if self.zeroborder_patch: os.system('cd %s && patch -N -p1 < ../../patch/yorick-cvs-pwin-border.patch' % patchdir)
class mkconfig_cmd(Command):
description = 'configure yorick prior to build'
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
log.info('making config')
patchdir=os.path.join(patch_work_dir,'yorick')
os.system('cd %s; make clean config;' % patchdir)
log.info('parse config')
libraries=[]
define_macros=[]
#include_dirs=[]
for line in open(os.path.join(patch_work_dir,'yorick/Make.cfg')):
if line.startswith('#'): continue
key,val=line.strip().split('=',1) # split first '='
if val != '':
if key == 'MATHLIB':
libraries.append(val.lstrip('-l'))
elif key == 'NO_EXP10':
define_macros.append((val.lstrip('-D'), None))
elif key == 'D_FPUSET':
define_macros.append((val.lstrip('-D'), None))
#elif key == 'XINC':
# include_dirs.append(val.lstrip('-I'))
#elif key == 'XLIB':
# libraries.append(val.lstrip('-L'))
# update our build_ext(s)
for ext in self.distribution.ext_modules:
ext.libraries.extend(libraries)
ext.define_macros.extend(define_macros)
#ext.include_dirs.extend(include_dirs)
class gist_build(build):
description = 'build python gist.'
def __init__(self, dist):
build.__init__(self, dist)
def has_patches(self):
# TODO return self.distribution.has_patches()
return True
sub_commands = [
('patch', has_patches ),
('mkconfig', lambda self:True ),
]
sub_commands.extend(build.sub_commands)
class Gist_dist(Distribution):
def __init__ (self, attrs=None):
#super(Gist_dist,self).__init__(attrs)
Distribution.__init__(self, attrs)
self.cmdclass = {
'build': gist_build, # override
'patch': patch_cmd,
'mkconfig': mkconfig_cmd,
}
long_description='''The Python Gist Scientific Graphics Package is a module for production of general scientific graphics. Gist is the graphic frontend for Yorick, written by David H. Munro of Lawrence Livermore National Laboratory. The library is small, portable, efficient, and full-featured. It produces x-vs-y plots with ``good'' tick marks and tick labels, 2-D quadrilateral mesh plots with contours, vector fields, or pseudocolor maps on such meshes, and a selection of 3-D plots.'''
if sys.version_info.major == 2: name='python-gist'
else: name='python%d-gist' % sys.version_info.major
setup(
name=name,
distclass=Gist_dist,
version=version,
description='gist for python.',
long_description=long_description,
author='Matthieu Bec',
author_email='[email protected]',
url='https://github.com/mdcb/python-gist',
license='GPLv3',
ext_modules=[
Extension(
name='gist.gistC',
sources=sources,
include_dirs=include_dirs,
#undef_macros=undef_macros,
define_macros=define_macros,
library_dirs=library_dirs,
libraries=libraries,
#runtime_library_dirs = ['xxx','yyy'],
extra_compile_args = extra_compile_args,
),
Extension(
name='gist.gistF',
sources=['plugin/gistfuncsmodule.c'],
include_dirs=include_dirs,
#undef_macros=undef_macros,
define_macros=define_macros,
library_dirs=library_dirs,
libraries=libraries,
#runtime_library_dirs = ['xxx','yyy'],
extra_compile_args = extra_compile_args,
),
],
packages = ['gist','gist.demo'],
package_dir = { 'gist': 'gist', 'gist.demo': 'gist/demo' },
data_files=data_files,
)