forked from andycasey/moog
-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
180 lines (137 loc) · 6.23 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
from distutils.core import setup
from distutils.sysconfig import get_python_lib
import os
import sys
import fileinput
import platform
import subprocess
from platform import system as current_platform
from shutil import copy, move, copytree
from glob import glob
__version__ = '2013.02'
# We need to build MOOG and MOOGSILENT before they get moved to the scripts/
# directory so that they can be moved into the $PATH
if 'install' in sys.argv:
# Identify the platform
platform = current_platform()
# Check for platform first
if platform not in ('Darwin', 'Linux'):
sys.stderr.write("Platform '%s' not recognised!\n" % platform)
sys.exit()
if os.getuid() != 0:
sys.stderr.write("Permission denied: Sudo access is required!\n")
sys.exit()
# We are sudo; with great power comes great responsibility.
# By default, we will use 32bit
is_64bits = False
# Which system are we on?
if platform == 'Darwin':
run_make_files = ('Makefile.mac', 'Makefile.macsilent')
machine = 'mac'
elif platform == 'Linux':
machine = 'pcl'
is_64bits = sys.maxsize > 2**32
if is_64bits:
run_make_files = ('Makefile.rh64', 'Makefile.rh64silent')
else:
run_make_files = ('Makefile.rh', 'Makefile.rhsilent')
# Check for gfortran or g77
def system_call(command):
""" Perform a system call with a subprocess pipe """
process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
return process.communicate()[0]
# Look for g77 and gfortran
g77_exists = len(system_call("which g77")) > 0
gfortran_exists = len(system_call("which gfortran")) > 0
# If we have the choice, use gfortran
if gfortran_exists:
if is_64bits:
fortran_vars = "FC = gfortran -m64\nFFLAGS = -Wall -O4 -ffixed-line-length-72 -ff2c"
else:
fortran_vars = "FC = gfortran\nFFLAGS = -Wall -O4 -ffixed-line-length-72 -ff2c"
elif g77_exists:
if platform == 'Linux':
fortran_vars = 'FC = g77 -Wall'
else:
fortran_vars = 'FC = g77 -w'
else:
sys.stderr.write("Could not find g77 or gfortran on the system!\n")
sys.exit()
# Get our directories relative to the current path
repository_dir = os.path.dirname(os.path.realpath(__file__))
# We need a moog data directory
data_dir = os.path.expanduser('/.moog')
if not os.path.exists(data_dir):
system_call('mkdir %s' % data_dir)
# Copy files to data directory
src_dir = os.path.join(repository_dir, 'moog')
data_files = glob('%s/*.dat' % src_dir)
[copy(data_file, '%s/%s' % (data_dir, os.path.basename(data_file), )) for data_file in data_files]
aqlib = "AQLIB = %s" % os.path.join(repository_dir, 'lib/aqlib')
smlib = "SMLIB = %s" % os.path.join(repository_dir, 'lib/smlib')
configuration = "\n".join([fortran_vars, aqlib, smlib])
# Update the makefiles with the proper SMLIB and AQLIB
run_make_files = [os.path.join(repository_dir, 'moog', filename) for filename in run_make_files]
hardcoded_moog_files = [os.path.join(repository_dir, 'moog', filename) for filename in ('Begin.f', 'Moog.f', 'Moogsilent.f')]
# Setup: Move and create copies of the original
for make_file in run_make_files:
move(make_file, make_file + '.original')
copy(make_file + '.original', make_file)
for moog_file in hardcoded_moog_files:
move(moog_file, moog_file + '.original')
copy(moog_file + '.original', moog_file)
# Update the run make files with the configuration
for line in fileinput.input(run_make_files, inplace=True):
line = line.replace('#$CONFIGURATION', configuration)
sys.stdout.write(line)
# Update the MOOG files
for line in fileinput.input(hardcoded_moog_files, inplace=True):
line = line.replace('$SRCDIR', src_dir)
line = line.replace('$DATADIR', data_dir)
line = line.replace('$MACHINE', machine)
sys.stdout.write(line)
# Run the appropriate make files
for make_file in run_make_files:
os.system('cd moog;make -f %s' % make_file)
# Cleanup files: Replace with original files
[move(moog_file + '.original', moog_file) for moog_file in hardcoded_moog_files if os.path.exists(moog_file + '.original')]
[move(make_file + '.original', make_file) for make_file in run_make_files if os.path.exists(make_file + '.original')]
# Copy the AquaTerm framework
if not os.path.exists('/Library/Frameworks/AquaTerm.framework/'):
try:
system_call('cp -R %s /Library/Frameworks/AquaTerm.framework/' % os.path.join(repository_dir, 'lib/AquaTerm.framework/'))
except:
sys.stdout.write("AquaTerm framework could not be installed to /Library/Frameworks/AquaTerm.framework\n")
else:
sys.stdout.write("AquaTerm framework copied to /Library/Frameworks/AquaTerm.framework\n")
# Distutils setup information
setup(
name='moog',
version=__version__,
author='Chris Sneden',
author_email='[email protected]',
maintainer='Andy Casey',
maintainer_email='[email protected]',
url='http://www.as.utexas.edu/~chris/moog.html',
download_url='http://github.com/andycasey/moog',
description='Spectrum synthesis and LTE line analysis.',
long_description='MOOG is a code that performs a variety of LTE line ' \
+'analysis and spectrum synthesis tasks. The typical use of MOOG is to' \
+' assist in the determination of the chemical composition of a star.',
keywords='high-resolution, stellar, spectroscopy, astronomy, astrophysics',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: MacOS X',
'Environment :: X11 Applications',
'Intended Audience :: Science/Research',
'Natural Language :: English',
'Operating System :: MacOS',
'Operating System :: POSIX',
'Operating System :: Unix',
'Programming Language :: Fortran',
'Programming Language :: Python :: 2.5',
'Topic :: Scientific/Engineering :: Astronomy',
'Topic :: Scientific/Engineering :: Physics',
],
scripts=['moog/MOOG', 'moog/MOOGSILENT'],
)