Skip to content

Commit b4c2c3b

Browse files
committed
Add rebound recipe
1 parent 2f2dfd6 commit b4c2c3b

5 files changed

Lines changed: 159 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--- a/setup.py 2026-07-02 13:26:02.036248410 +0200
2+
+++ b/setup.py 2026-07-02 13:26:13.421075170 +0200
3+
@@ -42,12 +42,17 @@
4+
extra_compile_args += ["-march=native", "-DAVX512"]
5+
6+
##### C Extension
7+
-libreboundmodule = Extension(
8+
- "librebound",
9+
- sources=sorted(glob("src/*.c")),
10+
- include_dirs=["src"],
11+
- extra_link_args=extra_link_args,
12+
- extra_compile_args=extra_compile_args,
13+
-)
14+
-
15+
-setup(ext_modules=[libreboundmodule])
16+
+# On emscripten, librebound is built and installed separately as a
17+
+# standalone shared library (see the librebound conda package).
18+
+# Skip building the C extension here; only install the Python wrapper.
19+
+if sys.platform == "emscripten":
20+
+ setup()
21+
+else:
22+
+ libreboundmodule = Extension(
23+
+ "librebound",
24+
+ sources=sorted(glob("src/*.c")),
25+
+ include_dirs=["src"],
26+
+ extra_link_args=extra_link_args,
27+
+ extra_compile_args=extra_compile_args,
28+
+ )
29+
+ setup(ext_modules=[libreboundmodule])
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--- a/rebound/__init__.py 2026-07-02 13:22:12.265323563 +0200
2+
+++ b/rebound/__init__.py 2026-07-02 13:30:16.171832835 +0200
3+
@@ -29,13 +29,23 @@
4+
except:
5+
pass
6+
7+
-# Import shared library
8+
-spec = importlib.util.find_spec("librebound")
9+
-if spec and spec.origin:
10+
- __libpath__ = spec.origin
11+
+# Import shared library.
12+
+# On emscripten, librebound is installed as a standalone shared library
13+
+# in the conda prefix (not as a Python extension module in site-packages).
14+
+# Load it directly from there. Use a fixed ".so" suffix because the
15+
+# library is built without Python ABI tags.
16+
+if sys.platform == "emscripten":
17+
+ import sysconfig as _sysconfig
18+
+ _prefix = _sysconfig.get_path("data")
19+
+ __libpath__ = os.path.join(_prefix, "lib", "librebound.so")
20+
clibrebound = cdll.LoadLibrary(__libpath__)
21+
else:
22+
- raise ImportError("librebound not found")
23+
+ spec = importlib.util.find_spec("librebound")
24+
+ if spec and spec.origin:
25+
+ __libpath__ = spec.origin
26+
+ clibrebound = cdll.LoadLibrary(__libpath__)
27+
+ else:
28+
+ raise ImportError("librebound not found")
29+
30+
# Version
31+
__version__ = c_char_p.in_dll(clibrebound, "reb_version_str").value.decode('ascii')
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--- a/rebound/horizons.py
2+
+++ b/rebound/horizons.py
3+
@@ -11,12 +11,11 @@
4+
5+
HORIZONSBASEURL = "https://ssd.jpl.nasa.gov/api/horizons.api?"
6+
7+
-if "pyodide" in sys.modules:
8+
- from urllib.parse import urlencode
9+
+try:
10+
from pyodide.http import open_url as urlopen
11+
- # Use CORS proxy
12+
+ from urllib.parse import urlencode
13+
HORIZONSBASEURL = "https://rebound.hanno-rein.de/api/horizons.api?"
14+
-else:
15+
+except ImportError:
16+
try:
17+
from urllib.parse import urlencode
18+
from urllib.request import urlopen
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
context:
2+
name: rebound
3+
version: 5.0.0
4+
5+
package:
6+
name: ${{ name }}
7+
version: ${{ version }}
8+
9+
source:
10+
- url: https://pypi.io/packages/source/${{ name[0] }}/${{ name }}/${{ name }}-${{ version }}.tar.gz
11+
sha256: 9012bc4ceac42da8c1344f54e72b64da4720149875dc069d8e0dd1be0285dc04
12+
patches:
13+
- patches/0001-skip-c-extension-on-emscripten.patch
14+
- patches/0002-load-librebound-from-prefix.patch
15+
- patches/0003-fix-pyodide-import.patch
16+
17+
build:
18+
number: 0
19+
script: ${PYTHON} -m pip install . ${PIP_ARGS} --no-deps --no-build-isolation
20+
21+
files:
22+
exclude:
23+
- '**/__pycache__/**'
24+
- '**/*.pyc'
25+
- '**/*.so'
26+
python:
27+
skip_pyc_compilation:
28+
- '**/*.py'
29+
30+
requirements:
31+
build:
32+
- cross-python_${{ target_platform }}
33+
- python
34+
- setuptools
35+
- wheel
36+
- pip
37+
host:
38+
- python
39+
run:
40+
- python
41+
- librebound
42+
43+
tests:
44+
- script: pytester
45+
files:
46+
recipe:
47+
- test_import_rebound.py
48+
requirements:
49+
build:
50+
- pytester
51+
run:
52+
- pytester-run
53+
- librebound
54+
55+
about:
56+
homepage: https://github.com/hannorein/rebound
57+
license: GPL-3.0-only
58+
license_file: LICENSE
59+
summary: An open-source multi-purpose N-body code
60+
documentation: https://rebound.hanno-rein.de
61+
62+
extra:
63+
recipe-maintainers:
64+
- mmesch
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
def test_import_rebound():
3+
import rebound
4+
assert rebound.__version__ == "5.0.0"
5+
6+
7+
def test_rebound_simulation():
8+
import rebound
9+
10+
sim = rebound.Simulation()
11+
sim.add(m=1.0)
12+
sim.add(m=1.0e-3, a=1.0)
13+
sim.integrate(100.0)
14+
15+
assert sim.N == 2
16+
orbit = sim.particles[1].orbit(primary=sim.particles[0])
17+
assert abs(orbit.a - 1.0) < 0.01

0 commit comments

Comments
 (0)