-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
94 lines (80 loc) · 2.68 KB
/
setup.py
File metadata and controls
94 lines (80 loc) · 2.68 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
from setuptools import setup, Extension, find_packages
try:
from Cython.Build import cythonize
except ImportError:
cythonize = None # If Cython is missing, pre-existing c files will be used
import sys
RELEASE_ARG = '--release'
DEBUG_ARG = '--debug'
CYTHONIZE_ARG = '--no-cythonize'
build_options_d = {
RELEASE_ARG: ('-O2', '-g3', '-Wall', '-Wextra', '-std=c99'),
DEBUG_ARG: ('-g3', '-Wall', '-Wextra', '-std=c99'),
}
def main():
release_mode = get_release_mode()
cythonization_option = get_cythonization_option()
build_options = build_options_d[release_mode]
def apply_cythonization_option(extensions):
if cythonization_option and cythonize:
return cythonize(extensions)
else:
for ext in extensions:
ext.sources = [
src[:-4] + '.c' if src.endswith('.pyx') else src
for src in ext.sources]
return extensions
setup(
name='pystargenplus',
version='0.0.2',
description='Stargen, simplified and wrapped in python',
install_requires=[
'setuptools>=38',
],
keywords='stargen',
packages=find_packages(exclude=['contrib', 'docs']),
libraries=[
# Contains logic from omega's development of the
# stargen program
('omega', {
'sources': [
'sgp/c/third_party/omega/stargen.c',
'sgp/c/third_party/omega/accrete.c',
'sgp/c/third_party/omega/Dumas.c',
'sgp/c/third_party/omega/enviro.c',
'sgp/c/third_party/omega/display.c',
'sgp/c/third_party/omega/utils.c',
],
'include_dirs': ['sgp/c/third_party/omega']
}),
],
ext_modules=apply_cythonization_option([
Extension(
name='sgp.stargen',
sources=[
'sgp/c/sgp.c',
'sgp/stargen.pyx',
],
libraries=['omega'],
include_dirs=['sgp/c', 'sgp/c/third_party/omega'],
extra_compile_args=[*build_options]
),
])
)
def get_release_mode():
release_mode = RELEASE_ARG
# find build option
if RELEASE_ARG in sys.argv:
sys.argv.remove(RELEASE_ARG)
if DEBUG_ARG in sys.argv:
sys.argv.remove(DEBUG_ARG)
release_mode = DEBUG_ARG
return release_mode
def get_cythonization_option():
option = True
if CYTHONIZE_ARG in sys.argv:
option = False
sys.argv.remove(CYTHONIZE_ARG)
return option
if __name__ == '__main__':
main()