-
Notifications
You must be signed in to change notification settings - Fork 13
/
setup.py
executable file
·162 lines (142 loc) · 5.76 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
#!/usr/bin/env python
import os, os.path, sys, glob
from fnmatch import fnmatch
try:
import numpy
except ImportError:
raise Exception("LSD requires numpy")
from distutils.core import setup, Extension
from distutils.command.build_py import build_py as _build_py
# Import version identifiers from lsd.version. This module
# generates them using git-describe
import imp
(fp, pathname, description) = imp.find_module('version', [ 'src/lsd' ])
version = imp.load_module('version', fp, pathname, description)
def write_version_file(outfile):
with file(outfile, 'w') as fp:
import textwrap
fp.write(textwrap.dedent(
"""\
# Do not edit. This file is regenerated by LSD's setup.py.
__all__ = [ '__version__', '__version_info__' ]
__version__ = %s
__version_info__ = %s
""" % (repr(version.__version__), repr(version.__version_info__))))
from distutils.command.sdist import sdist as _sdist
class sdist(_sdist):
def copy_file(self, infile, outfile, preserve_mode=1, preserve_times=1, link=None, level=1):
if infile == 'src/lsd/version.py':
write_version_file(outfile)
else:
_sdist.copy_file(self, infile, outfile, preserve_mode, preserve_times, link, level)
class build_py(_build_py):
""" An override for build_py that records the location
where the package was installed into lsd.config
module variables, and records the version information.
"""
def build_module (self, module, module_file, package):
if package == 'lsd.config' and 'install' in self.distribution.command_obj:
iobj = self.distribution.command_obj['install']
outfile = self.get_module_outfile(self.build_lib, package.split('.'), module)
dir = os.path.dirname(outfile)
self.mkpath(dir)
with file(outfile, 'w') as fp:
import textwrap
fp.write(textwrap.dedent(
"""\
# Do not edit. This file is regenerated by LSD's setup.py.
data_dir = '{datadir}'
bin_dir = '{bindir}'
""").format(datadir=os.path.join(iobj.install_data, 'share', 'lsd', 'data'), bindir=iobj.install_scripts))
return (outfile, 1)
elif module == 'version' and module_file == 'src/lsd/version.py':
# Load the version information from developer module (which gets it
# from git), and write out the install module that is git independent.
# Store it to a generated file
outfile = self.get_module_outfile(self.build_lib, package.split('.'), module)
dir = os.path.dirname(outfile)
self.mkpath(dir)
write_version_file(outfile)
return (outfile, 1)
else:
return _build_py.build_module(self, module, module_file, package)
def get_filelist(dir):
# Recursively list the files not beginning with a '.' in the
# given directory, and return it as a list of (dir, files_in_dir)
# tuples, one tuple for each subdirectory of dir (as well as
# dir itself). This format is suitable for passing to distutils'
# 'data_files' setup keyword.
#
def get_filelist_aux(dir, res):
contents = []
for f in os.listdir(dir):
if f.startswith('.'):
continue
path = os.path.join(dir, f)
if os.path.isdir(path):
get_filelist_aux(path, res)
if os.path.isfile(path):
contents.append(path)
if contents:
res[dir] = contents
res = {}
get_filelist_aux(dir, res)
return res.items()
# Enumerate data files that are to be copied to /share/lsd/data. Format them the way disttools wants it.
if os.path.isdir('src/data'):
data_files = [ (os.path.join('share', 'lsd', *dest.split('/')[1:]), f) for dest, f in get_filelist('src/data') ]
else:
data_files = []
# Filter only a "necessary" subset of all data. The user can download the whole lsd-data package
# if they're interested. (TODO: provide an automated way to do this)
data_files_whitelist = { } # 'src/data/sfd-dust-maps/SFD_dust_4096_*.fits'
data_files2 = []
for to, files in data_files:
f2 = []
for f in files:
f2 += [ f for pat in data_files_whitelist if fnmatch(f, pat) ]
if f2:
data_files2.append((to, f2))
data_files = data_files2
inc = [ numpy.get_include() ]
longdesc = """Large Survey Database"""
args = {
'cmdclass' : { 'build_py' : build_py, 'sdist' : sdist },
'name' : "lsd",
'version' : version.__version__,
'description' : "Large Survey Database Python Module",
'long_description' : longdesc,
'license' : "GPLv2",
'author' : "Mario Juric",
'author_email' : "[email protected]",
'maintainer' : "Mario Juric",
'maintainer_email' : "[email protected]",
'url' : "http://mwscience.net/lsd",
'download_url' : "http://mwscience.net/lsd/download",
'classifiers' : [
'Development Status :: 3 - Alpha',
'Intended Audience :: Science/Research',
'Intended Audience :: Developers',
'License :: OSI Approved :: GNU General Public License (GPL)',
'Programming Language :: C++',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Operating System :: POSIX :: Linux',
'Topic :: Database',
'Topic :: Scientific/Engineering :: Astronomy'
],
'scripts' : ['src/lsd-footprint', 'src/lsd-import-sdss', 'src/lsd-make-object-catalog',
'src/lsd-import-dvo', 'src/lsd-import-smf',
'src/lsd-query', 'src/lsd-xmatch', 'src/mr-peer',
'src/lsd-manager', 'src/lsd-admin', 'src/lsd-import',
'src/lsd-check'],
'packages' : ['lsd', 'lsd.builtins', 'lsd.importers', 'surveys', 'surveys.ps1', 'surveys.sdss', 'mr', 'lsd.config'],
'package_dir' : {'': 'src'},
'ext_modules' : [Extension('lsd.native', ['src/native/main.cpp'], include_dirs=inc)],
'data_files' : [
('share/lsd/examples', ['src/examples/latitude_histogram.py', 'src/examples/count_rows.py']),
('share/lsd/schemas', glob.glob('src/schemas/*.yaml') + glob.glob('src/schemas/*.map')),
('share/lsd/data', ['src/README.data'])
] + data_files
}
setup(**args)