forked from iraf-community/pyraf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefsetup.py
More file actions
240 lines (198 loc) · 8.19 KB
/
defsetup.py
File metadata and controls
240 lines (198 loc) · 8.19 KB
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
#!/usr/bin/env python
from __future__ import division # confidence high
import os, os.path, shutil, sys, commands
import distutils.core
import distutils.sysconfig
import string
## conditional flags, defaults
# conditional for if we are running on Windows
ms_windows = sys.platform.startswith('win')
# conditional for if we should build the C code
build_c = not ms_windows
# so my 2.5 fink build works:
if sys.version_info[:2] < (2,6):
build_c = False
ms_windows = True
C_EXT_MODNAME_ENDING = 'module'
if sys.version_info[0] > 2: # actually changes in Python 3.3, but why wait
C_EXT_MODNAME_ENDING = '' # needs not "sscanfmodule.so", but "sscanf.so"
# default to no C extensions; add to this list when necessary
PYRAF_EXTENSIONS = []
# get the python libraries for use by C extensions
# (why? doesn't distutils already reference those?)
add_lib_dirs = [ distutils.sysconfig.get_python_lib(plat_specific=1, standard_lib = 1) ]
add_inc_dirs = [ distutils.sysconfig.get_python_inc(plat_specific=1) ]
## x windows specific features
x_libraries = 'X11'
def find_x(xdir=""):
if xdir != "":
add_lib_dirs.append(os.path.join(xdir,'lib64'))
add_lib_dirs.append(os.path.join(xdir,'lib'))
add_inc_dirs.append(os.path.join(xdir,'include'))
elif sys.platform == 'darwin' or sys.platform.startswith('linux'):
add_lib_dirs.append('/usr/X11R6/lib64')
add_lib_dirs.append('/usr/X11R6/lib')
add_inc_dirs.append('/usr/X11R6/include')
elif sys.platform == 'sunos5' :
add_lib_dirs.append('/usr/openwin/lib')
add_inc_dirs.append('/usr/openwin/include')
else:
try:
import Tkinter
except:
raise ImportError("Tkinter is not installed")
tk=Tkinter.Tk()
tk.withdraw()
tcl_lib = os.path.join(str(tk.getvar('tcl_library')), '../')
tcl_inc = os.path.join(str(tk.getvar('tcl_library')), '../../include')
tk_lib = os.path.join(str(tk.getvar('tk_library')), '../')
tkv = str(Tkinter.TkVersion)[:3]
# yes, the version number of Tkinter really is a float...
if Tkinter.TkVersion < 8.3:
print "Tcl/Tk v8.3 or later required\n"
sys.exit(1)
else:
suffix = '.so'
tklib='libtk'+tkv+suffix
command = "ldd %s" % (os.path.join(tk_lib, tklib))
lib_list = string.split(commands.getoutput(command))
for lib in lib_list:
if string.find(lib, 'libX11') == 0:
ind = lib_list.index(lib)
add_lib_dirs.append(os.path.dirname(lib_list[ind + 2]))
#break
add_inc_dirs.append(os.path.join(os.path.dirname(lib_list[ind + 2]), '../include'))
if not ms_windows :
# Should we do something about X if we're using aqua on a mac?
# Apparently it doesn't cause any problems.
find_x()
#
def dir_clean(list) :
# We have a list of directories. Remove any that don't exist.
r = [ ]
for x in list :
if os.path.isdir(x) :
r.append(x)
return r
add_lib_dirs = dir_clean(add_lib_dirs)
add_inc_dirs = dir_clean(add_inc_dirs)
## C extensions
# by default, we don't build any C extensions on MS Windows. The
# user probably does not have a compiler, and these extensions just
# aren't that important.
if not ms_windows or build_c :
# windows users have to do without the CL sscanf() function,
# unless you explicitly set build_c true.
PYRAF_EXTENSIONS.append(
distutils.core.Extension(
'pyraf.sscanf'+C_EXT_MODNAME_ENDING,
['src/sscanfmodule.c'],
# extra_compile_args = ['-arch','i386','-arch','x86_64'],
# extra_link_args = ['-arch','i386','-arch','x86_64'],
include_dirs=add_inc_dirs
)
)
if not ms_windows :
# windows users do not have X windows, so we never need the X
# support
PYRAF_EXTENSIONS.append(
distutils.core.Extension(
'pyraf.xutil'+C_EXT_MODNAME_ENDING,
['src/xutil.c'],
include_dirs=add_inc_dirs,
library_dirs=add_lib_dirs,
# extra_compile_args = ['-arch','i386','-arch','x86_64'],
# extra_link_args = ['-arch','i386','-arch','x86_64'],
libraries = [x_libraries]
)
)
## what scripts do we install
if ms_windows :
# On windows, you use "runpyraf.py" - it can't be pyraf.py
# because then you can't "import pyraf" in the script.
# Instead, you ( double-click the icon for runpyraf.py ) or
# ( type "runpyraf.py" ) or ( type "pyraf" to get pyraf.bat ).
# adapt to installing in the pyraf package or installing stsci_python
if os.path.exists('pyraf'):
scriptdir = [ 'pyraf', 'scripts' ]
else :
scriptdir = [ 'scripts' ]
# copy the pyraf main program to the name we want it installed as
shutil.copy(
os.path.join( * ( scriptdir + [ 'pyraf' ] ) ) ,
os.path.join( * ( scriptdir + [ 'runpyraf.py' ] ) )
)
# list of scripts for windows
scriptlist = ['scripts/runpyraf.py', 'scripts/pyraf.bat']
else :
# on linux/mac, you have just the one main program
scriptlist = ['scripts/pyraf' ]
## icon on the desktop
if ms_windows :
# Install optional launcher onto desktop
if 'USERPROFILE' in os.environ:
dtop = os.environ['USERPROFILE']+os.sep+'Desktop'
if os.path.exists(dtop):
shortcut = dtop+os.sep+"PyRAF.bat"
if os.path.exists(shortcut):
os.remove(shortcut)
target = sys.exec_prefix+os.sep+"Scripts"+os.sep+"runpyraf.py"
f = open(shortcut, 'w')
f.write('@echo off\necho.\ncd %APPDATA%\n')
f.write('echo Launching PyRAF ...\necho.\n')
f.write(target)
f.write('\necho.\npause\n')
f.close()
print('Installing PyRAF.bat to -> '+dtop)
else:
print('Error: User desktop not found at: '+dtop)
else:
print('Error: User desktop location unknown')
# NOTE: a much better solution would be to use something (bdist) to
# create installer binaries for Windows, since they are: 1) easier on
# the win user, and 2) can be used to create actual desktop shortcuts,
# not this kludgy .bat file. If we take out the two libraries built
# from the bdist run (which aren't used on Win anyway) then we can
# automate this build from Linux (yes, for Windows), via:
# python setup.py bdist_wininst --no-target-compile --plat-name=win32
# and
# python setup.py bdist_wininst --no-target-compile --plat-name=win-amd64
# We would need to provide both 32- and 64-bit versions since the
# installer will fail gracelessly if you try to install one and the Win
# node only has the other (listed in its registry). The above 64-bit bdist
# fails currently on thor but the 32-bit bdist works. Need to investigate.
# Another option to create the shortcut is to bundle win32com w/ installer.
## the defsetup interface is here:
## pkg
pkg = "pyraf"
# data files
DATA_FILES = [ ( pkg,
['data/blankcursor.xbm',
'data/epar.optionDB',
'data/pyraflogo_rgb_web.gif',
'data/ipythonrc-pyraf',
'LICENSE.txt',
]
)
]
if not ms_windows and sys.version_info[0] < 3:
# clcache is a pre-loaded set of CL files already converted to
# python. There are none on Windows, so we don't need them.
# We also are not yet using them in PY3K.
# Leaving them out makes the install go a lot faster.
DATA_FILES += [
(pkg+'/clcache', [ "data/clcache/*" ] )
]
## setupargs
setupargs = {
'version' : "2.x", # see lib's __init__.py
'description' : "A Python based CL for IRAF",
'author' : "Rick White, Perry Greenfield, Chris Sontag",
'url' : "http://www.stsci.edu/resources/software_hardware/pyraf",
'license' : "http://www.stsci.edu/resources/software_hardware/pyraf/LICENSE",
'platforms' : ["unix"],
'data_files' : DATA_FILES,
'scripts' : scriptlist,
'ext_modules' : PYRAF_EXTENSIONS,
'package_dir' : { 'pyraf' : 'lib/pyraf' },
}