-
Notifications
You must be signed in to change notification settings - Fork 19
/
setup.py
220 lines (191 loc) · 7.92 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
# -*- coding: utf-8 -*-
import codecs
import os
import platform
from distutils.core import setup, Extension
from distutils.core import Command
from distutils.command.build_clib import build_clib
from distutils.sysconfig import get_python_lib
from distutils import log
from asc2eph import download_ascii, process_header, process_data_files
class build_dynamic_clib(build_clib):
def finalize_options (self):
self.set_undefined_options('build',
('build_lib', 'build_clib'),
('build_temp', 'build_temp'),
('compiler', 'compiler'),
('debug', 'debug'),
('force', 'force'))
self.libraries = self.distribution.libraries
if self.libraries:
self.check_library_list(self.libraries)
if self.include_dirs is None:
self.include_dirs = self.distribution.include_dirs or []
if isinstance(self.include_dirs, str):
self.include_dirs = self.include_dirs.split(os.pathsep)
def build_libraries (self, libraries):
for (lib_name, build_info) in libraries:
sources = build_info.get('sources')
if sources is None or not isinstance(sources, (list, tuple)):
raise DistutilsSetupError(
"in 'libraries' option (library '%s'), "
"'sources' must be present and must be "
"a list of source filenames" % lib_name)
sources = list(sources)
log.info("building '%s' library", lib_name)
macros = build_info.get('macros')
include_dirs = build_info.get('include_dirs')
objects = self.compiler.compile(sources,
output_dir=self.build_temp,
macros=macros,
include_dirs=include_dirs,
extra_postargs=build_info.get('extra_compile_args', []),
debug=self.debug)
package = build_info.get('package', '')
self.compiler.link_shared_lib(
objects, lib_name,
output_dir=os.path.join(self.build_clib, package),
extra_postargs=build_info.get('extra_link_args', []),
debug=self.debug,)
def run(self):
log.info('running build_dynamic_clib')
build_clib.run(self)
class build_ephemeris(Command):
description = 'build a default DE405 binary for installation with the \
NOVAS Py package'
user_options = [
('build-temp=', 't',
'temporary build directory'),
('ephemeris-dir=', 'e',
'ephemeris file directory')
]
def initialize_options(self):
self.build_temp = None
self.ephemeris_dir = None
def finalize_options(self):
if self.build_temp is None:
build = self.get_finalized_command('build')
self.build_temp = os.path.join(build.build_temp, 'ephemeris')
self.mkpath(self.build_temp)
if self.ephemeris_dir is None:
self.ephemeris_dir = calling_dir
else:
self.mkpath(os.path.abspath(os.path.join(calling_dir,
self.ephemeris_dir)))
def create_ephemeris(self, de_number=405):
try:
download_ascii(self.build_temp, de_number)
binary_file = open(os.path.join(self.ephemeris_dir, "DE%s.bin") %
de_number, 'wb')
ncoeff = process_header(self.build_temp, de_number, binary_file)
data_files = [os.path.join(self.build_temp, "ascp%d.%s" %
(year, de_number)) for year in
range(1600, 2220, 20)]
process_data_files(data_files, ncoeff, binary_file)
binary_file.close()
finally:
pass
def run(self):
log.info('running build_ephemeris')
self.create_ephemeris()
c_sources = [
'Cdist/solsys1.c',
'Cdist/readeph0.c',
'Cdist/eph_manager.c',
'Cdist/nutation.c',
'Cdist/novascon.c',
'Cdist/novas.c'
]
calling_dir = None
def main():
global calling_dir
calling_dir = os.getcwd()
cwd = os.path.dirname(__file__)
if cwd:
os.chdir(cwd)
system = platform.system().lower()
if 'darwin' in system:
novaslib = [(
'novas', {
'package': 'novas',
'sources': c_sources,
'include_dirs': ['Cdist'],
'extra_compile_args': ['-arch', 'i386',
'-arch', 'x86_64',
'-arch', 'arm64',
'-O2', '-Wall', '-fPIC']
}
)]
elif 'windows' in system:
raise OSError("Operating system not supported at this time")
else:
novaslib = [(
'novas', {
'package': 'novas',
'sources': c_sources,
'include_dirs': ['Cdist'],
'extra_compile_args': ['-O2', '-Wall', '-fPIC']
}
)]
options = {
'name': 'NOVAS_Py',
'version': '3.1.1',
'description': "Python wrappers for the US Naval Observatory's \
NOVAS-C package.",
'author': 'Eric G. Barron',
'author_email': "%(firstdotlast)s@%(place)s" %
{'firstdotlast': 'eric.barron',
'place': 'usno.navy.mil'},
'maintainer': 'Eric G. Barron',
'maintainer_email': "%(firstdotlast)s@%(place)s" %
{'firstdotlast': 'eric.barron',
'place': 'usno.navy.mil'},
'url': 'http://www.usno.navy.mil/USNO/astronomical-applications/software-products/novas',
'download_url' : 'http://www.usno.navy.mil/USNO/astronomical-applications/software-products/novas',
'platforms': ['macosx', 'linux'],
'classifiers': [
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Science/Research',
'Natural Language :: English',
'Operating System :: MacOS :: MacOS X',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Topic :: Scientific/Engineering :: Astronomy',
],
'packages': ['novas', 'novas.compat'],
'package_dir': {
'novas': 'novas_py',
'novas.compat': 'compat'
},
'libraries': novaslib,
'cmdclass': {
'build_clib': build_dynamic_clib,
}
}
# Begin customizations by Brandon Rhodes for release on PyPI
options['name'] = 'novas'
options['version'] = '3.1.1.6'
options['description'] = ('The United States Naval Observatory'
' NOVAS astronomy library')
options['long_description'] = (codecs.open('README-PyPI', 'r', 'utf-8')
.read())
options['maintainer'] = (options['author'] +
'; packaged for PyPI by Brandon Rhodes')
options['maintainer_email'] = '[email protected]'
options['packages'].append('novas.tests')
options['package_dir']['novas.tests'] = 'tests'
del options['download_url']
# End customizations by Brandon Rhodes for release on PyPI
setup(**options)
if __name__ == '__main__':
main()