Skip to content

Commit 53d71f2

Browse files
committed
updated python build system
1 parent 6dd4e3c commit 53d71f2

File tree

2 files changed

+79
-116
lines changed

2 files changed

+79
-116
lines changed

pyproject.toml

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,40 @@
11
[build-system]
2-
requires = ["setuptools >= 59.0.0"]
2+
requires = ["setuptools>=64", "wheel"]
33
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "rebound"
7+
version = "5.0.0"
8+
description = "An open-source multi-purpose N-body code"
9+
readme = { file = "README.md", content-type = "text/markdown" }
10+
license = "GPL-3.0-only"
11+
authors = [
12+
{ name = "Hanno Rein", email = "hanno@hanno-rein.de" },
13+
]
14+
keywords = [
15+
"astronomy",
16+
"astrophysics",
17+
"nbody",
18+
"integrator",
19+
"symplectic",
20+
"wisdom-holman",
21+
]
22+
classifiers = [
23+
"Development Status :: 5 - Production/Stable",
24+
"Intended Audience :: Science/Research",
25+
"Intended Audience :: Developers",
26+
"Topic :: Software Development :: Build Tools",
27+
"Topic :: Scientific/Engineering :: Astronomy",
28+
"Programming Language :: Python :: 3",
29+
]
30+
requires-python = ">=3.7"
31+
dependencies = []
32+
33+
[project.urls]
34+
Homepage = "https://github.com/hannorein/rebound/"
35+
36+
[tool.setuptools.packages.find]
37+
include = ["rebound", "rebound.*"]
38+
39+
[tool.setuptools.package-data]
40+
rebound = ["include/*.h"]

setup.py

Lines changed: 41 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,53 @@
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
76
import os
87
import sys
9-
108
import sysconfig
11-
suffix = sysconfig.get_config_var('EXT_SUFFIX')
12-
if suffix is None:
13-
suffix = ".so"
149

15-
# Try to get git hash
10+
##### Git hash
1611
try:
1712
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"]
3029
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"]
3834
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")
8836

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")
9240

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"]
10843

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+
)
11452

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

Comments
 (0)