|
1 | | -try: |
2 | | - from setuptools import setup, Extension |
3 | | -except ImportError: |
4 | | - # Legacy distutils import. No longer available on Python > 3.12 |
5 | | - from distutils.core import setup, Extension |
6 | | -from codecs import open |
| 1 | +# This file exists solely to configure the dynamic C extension. |
| 2 | +# All project metadata lives in pyproject.toml. |
| 3 | + |
| 4 | +from setuptools import setup, Extension |
| 5 | +from glob import glob |
7 | 6 | import os |
8 | 7 | import sys |
9 | | - |
10 | 8 | import sysconfig |
11 | | -suffix = sysconfig.get_config_var('EXT_SUFFIX') |
12 | | -if suffix is None: |
13 | | - suffix = ".so" |
14 | 9 |
|
15 | | -# Try to get git hash |
| 10 | +##### Git hash |
16 | 11 | try: |
17 | 12 | import subprocess |
18 | | - ghash = subprocess.check_output(["git", "rev-parse", "HEAD"]).decode("ascii") |
19 | | - ghash_arg = "-DGITHASH="+ghash.strip() |
20 | | -except: |
21 | | - ghash_arg = "-DGITHASH=16889b7f9d2381f2aa3ac1571e4a548343ef15ce" #GITHASHAUTOUPDATE |
22 | | - |
23 | | -extra_link_args=[] |
24 | | -if sys.platform == 'darwin': |
25 | | - config_vars = sysconfig.get_config_vars() |
26 | | - config_vars['LDSHARED'] = config_vars['LDSHARED'].replace('-bundle', '-shared') |
27 | | - extra_link_args=['-Wl,-install_name,@rpath/librebound'+suffix] |
28 | | -if sys.platform == 'win32': |
29 | | - extra_compile_args=[ghash_arg, '-DLIBREBOUND', '-D_GNU_SOURCE', '-DSERVER'] |
| 13 | + ghash = subprocess.check_output(["git", "rev-parse", "HEAD"]).decode("ascii").strip() |
| 14 | + ghash_arg = f"-DGITHASH={ghash}" |
| 15 | +except Exception: |
| 16 | + ghash_arg = "-DGITHASH=16889b7f9d2381f2aa3ac1571e4a548343ef15ce" # GITHASHAUTOUPDATE |
| 17 | + |
| 18 | +##### Link args |
| 19 | +extra_link_args = [] |
| 20 | +if sys.platform == "darwin": |
| 21 | + cfg = sysconfig.get_config_vars() |
| 22 | + cfg["LDSHARED"] = cfg["LDSHARED"].replace("-bundle", "-shared") |
| 23 | + suffix = sysconfig.get_config_var("EXT_SUFFIX") or ".so" |
| 24 | + extra_link_args = [f"-Wl,-install_name,@rpath/librebound{suffix}"] |
| 25 | + |
| 26 | +##### Compile args |
| 27 | +if sys.platform == "win32": |
| 28 | + extra_compile_args = [ghash_arg, "-DLIBREBOUND", "-D_GNU_SOURCE", "-DSERVER"] |
30 | 29 | else: |
31 | | - # Default compile args |
32 | | - extra_compile_args=['-fstrict-aliasing', '-std=c99','-Wno-unknown-pragmas', ghash_arg, '-DLIBREBOUND', '-D_GNU_SOURCE', '-DSERVER', '-fPIC'] |
33 | | - # For coverage runs, turn off optimizations and turn on coverage generation |
34 | | - COVERAGE = os.environ.get("COVERAGE", None) |
35 | | - if COVERAGE: |
36 | | - extra_compile_args += ['-O1', '-fprofile-arcs', '-ftest-coverage' ,'-coverage'] |
37 | | - extra_link_args += ['-fprofile-arcs', '-ftest-coverage' ,'-coverage'] |
| 30 | + extra_compile_args = [ "-fstrict-aliasing", "-std=c99", "-Wno-unknown-pragmas", ghash_arg, "-D_GNU_SOURCE", "-DSERVER", "-fPIC"] |
| 31 | + if os.environ.get("COVERAGE"): |
| 32 | + extra_compile_args += ["-O1", "-fprofile-arcs", "-ftest-coverage", "-coverage"] |
| 33 | + extra_link_args += ["-fprofile-arcs", "-ftest-coverage", "-coverage"] |
38 | 34 | else: |
39 | | - extra_compile_args += ['-O3'] |
40 | | - |
41 | | -# Option to disable FMA in CLANG. |
42 | | -FFP_CONTRACT_OFF = os.environ.get("FFP_CONTRACT_OFF", None) |
43 | | -if FFP_CONTRACT_OFF: |
44 | | - extra_compile_args.append('-ffp-contract=off') |
45 | | - |
46 | | -# Option to enable AVX512 enabled integrators (WHFast512). |
47 | | -AVX512 = os.environ.get("AVX512", None) |
48 | | -if AVX512: |
49 | | - extra_compile_args.append('-march=native') |
50 | | - extra_compile_args.append('-DAVX512') |
51 | | - |
52 | | -libreboundmodule = Extension('librebound', |
53 | | - sources = [ 'src/rebound.c', |
54 | | - 'src/integrator_ias15.c', |
55 | | - 'src/integrator_whfast.c', |
56 | | - 'src/integrator_whfast512.c', |
57 | | - 'src/integrator_saba.c', |
58 | | - 'src/integrator_mercurius.c', |
59 | | - 'src/integrator_trace.c', |
60 | | - 'src/integrator_eos.c', |
61 | | - 'src/integrator_leapfrog.c', |
62 | | - 'src/integrator_bs.c', |
63 | | - 'src/integrator_janus.c', |
64 | | - 'src/integrator_sei.c', |
65 | | - 'src/integrator.c', |
66 | | - 'src/gravity.c', |
67 | | - 'src/server.c', |
68 | | - 'src/frequency_analysis.c', |
69 | | - 'src/boundary.c', |
70 | | - 'src/display.c', |
71 | | - 'src/collision.c', |
72 | | - 'src/tools.c', |
73 | | - 'src/fmemopen.c', |
74 | | - 'src/rotations.c', |
75 | | - 'src/simulation.c', |
76 | | - 'src/derivatives.c', |
77 | | - 'src/tree.c', |
78 | | - 'src/particle.c', |
79 | | - 'src/binarydata.c', |
80 | | - 'src/output.c', |
81 | | - 'src/simulationarchive.c', |
82 | | - 'src/transformations.c', |
83 | | - ], |
84 | | - include_dirs = ['src'], |
85 | | - extra_link_args=extra_link_args, |
86 | | - extra_compile_args=extra_compile_args, |
87 | | - ) |
| 35 | + extra_compile_args.append("-O3") |
88 | 36 |
|
89 | | -here = os.path.abspath(os.path.dirname(__file__)) |
90 | | -with open(os.path.join(here, 'README.md'), encoding='utf-8') as f: |
91 | | - long_description = f.read() |
| 37 | +##### Turn off floating point contractions for bitwise reproducibility |
| 38 | +if os.environ.get("FFP_CONTRACT_OFF"): |
| 39 | + extra_compile_args.append("-ffp-contract=off") |
92 | 40 |
|
93 | | -setup(name='rebound', |
94 | | - version='5.0.0', |
95 | | - description='An open-source multi-purpose N-body code', |
96 | | - long_description=long_description, |
97 | | - long_description_content_type="text/markdown", |
98 | | - url='https://github.com/hannorein/rebound/', |
99 | | - author='Hanno Rein', |
100 | | - author_email='hanno@hanno-rein.de', |
101 | | - license_expression="GPL-3.0-only", |
102 | | - classifiers=[ |
103 | | - # How mature is this project? Common values are |
104 | | - # 3 - Alpha |
105 | | - # 4 - Beta |
106 | | - # 5 - Production/Stable |
107 | | - 'Development Status :: 5 - Production/Stable', |
| 41 | +if os.environ.get("AVX512"): |
| 42 | + extra_compile_args += ["-march=native", "-DAVX512"] |
108 | 43 |
|
109 | | - # Indicate who your project is intended for |
110 | | - 'Intended Audience :: Science/Research', |
111 | | - 'Intended Audience :: Developers', |
112 | | - 'Topic :: Software Development :: Build Tools', |
113 | | - 'Topic :: Scientific/Engineering :: Astronomy', |
| 44 | +##### C Extension |
| 45 | +libreboundmodule = Extension( |
| 46 | + "librebound", |
| 47 | + sources=sorted(glob("src/*.c")), |
| 48 | + include_dirs=["src"], |
| 49 | + extra_link_args=extra_link_args, |
| 50 | + extra_compile_args=extra_compile_args, |
| 51 | +) |
114 | 52 |
|
115 | | - # Specify the Python versions you support here. In particular, ensure |
116 | | - # that you indicate whether you support Python 2, Python 3 or both. |
117 | | - 'Programming Language :: Python :: 2', |
118 | | - 'Programming Language :: Python :: 3', |
119 | | - ], |
120 | | - keywords='astronomy astrophysics nbody integrator symplectic wisdom-holman', |
121 | | - packages=['rebound', 'rebound.integrators'], |
122 | | - package_data = {'rebound':['include/*.h']}, |
123 | | - install_requires=[], |
124 | | - tests_require=["numpy","matplotlib"], |
125 | | - test_suite="rebound.tests", |
126 | | - ext_modules = [libreboundmodule], |
127 | | - zip_safe=False) |
| 53 | +setup(ext_modules=[libreboundmodule]) |
0 commit comments