forked from esheldon/fitsio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
113 lines (87 loc) · 3.18 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
import distutils
from distutils.core import setup, Extension, Command
import os
import numpy
import glob
import shutil
import platform
package_basedir = os.path.abspath(os.curdir)
cfitsio_version = '3280patch'
cfitsio_dir = 'cfitsio%s' % cfitsio_version
cfitsio_build_dir = os.path.join('build',cfitsio_dir)
makefile = os.path.join(cfitsio_build_dir, 'Makefile')
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 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)
def configure_cfitsio():
os.chdir(cfitsio_build_dir)
ret=os.system('sh ./configure')
if ret != 0:
raise ValueError("could not configure cfitsio %s" % cfitsio_version)
os.chdir(package_basedir)
def compile_cfitsio():
os.chdir(cfitsio_build_dir)
ret=os.system('make')
if ret != 0:
raise ValueError("could not compile cfitsio %s" % cfitsio_version)
os.chdir(package_basedir)
if not os.path.exists('build'):
ret=os.makedirs('build')
if not os.path.exists(cfitsio_build_dir):
ret=os.makedirs(cfitsio_build_dir)
copy_update(cfitsio_dir, cfitsio_build_dir)
if not os.path.exists(makefile):
configure_cfitsio()
compile_cfitsio()
data_files=[]
# when using "extra_objects" in Extension, changes in the objects do *not*
# cause a re-link! The only way I know is to force a recompile by removing the
# directory
build_libdir=glob.glob(os.path.join('build','lib*'))
if len(build_libdir) > 0:
shutil.rmtree(build_libdir[0])
sources = ["fitsio/fitsio_pywrap.c","fitsio/fitsio_pywrap_lists.c"]
extra_objects = glob.glob(os.path.join(cfitsio_build_dir,'*.o'))
if platform.system()=='Darwin':
extra_compile_args=['-arch','i386','-arch','x86_64']
extra_link_args=['-arch','i386','-arch','x86_64']
else:
extra_compile_args=[]
extra_link_args=[]
ext=Extension("fitsio._fitsio_wrap",
sources,
extra_objects=extra_objects,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args)
description = ("A full featured python library to read and "
"write data to FITS files.")
long_description=open(os.path.join(os.path.dirname(__file__), "README.md")).read()
classifiers = ["Development Status :: 5 - Production/Stable"
,"License :: OSI Approved :: GNU General Public License (GPL)"
,"Topic :: Scientific/Engineering :: Astronomy"
,"Intended Audience :: Science/Research"
]
include_dirs=[cfitsio_dir,numpy.get_include()]
setup(name="fitsio",
version="0.9.3",
description=description,
long_description=long_description,
license = "GPL",
classifiers=classifiers,
url="https://github.com/esheldon/fitsio",
author="Erin Scott Sheldon",
author_email="[email protected]",
install_requires=['numpy'],
packages=['fitsio'],
data_files=data_files,
ext_modules=[ext],
include_dirs=include_dirs)