Skip to content

Commit 5d45632

Browse files
committed
Create amuse_examples package and forwards from amuse.examples
1 parent 89f45c2 commit 5d45632

81 files changed

Lines changed: 122 additions & 5 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/amuse/examples/__init__.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
""" Forward examples
2+
3+
This does not use amuse.support.helpers.load_symbol, because we don't have an interface.py
4+
and because we want to have different error messages. We're not loading a code, in
5+
short.
6+
"""
7+
from importlib import import_module
8+
from os import environ
9+
10+
11+
def _load_symbol(symbol):
12+
try:
13+
module = import_module("amuse_examples")
14+
except ImportError:
15+
msg = f"Error: The examples are not installed."
16+
if "CONDA_PREFIX" in environ:
17+
env = environ["CONDA_DEFAULT_ENV"]
18+
msg += (
19+
" To install the examples go to the terminal, make sure that"
20+
f" the '{env}' conda environment is active and that you are in the"
21+
" amuse source directory, then install them using './setup"
22+
" install amuse-examples' and restart your script or reload the"
23+
" kernel.")
24+
25+
if "VIRTUAL_ENV" in environ:
26+
env = environ["VIRTUAL_ENV"]
27+
msg += (
28+
" To install the examples, go to the terminal, make sure that"
29+
f" the '{env}' virtual environment is active and that you are in"
30+
" the amuse source directory, then install the code using './setup"
31+
" install amuse-examples' and restart your script or reload the"
32+
" kernel.")
33+
raise ImportError(msg) from None
34+
35+
try:
36+
return vars(module)[symbol]
37+
except KeyError:
38+
raise ImportError(
39+
f"cannot import '{symbol}' from 'amuse_examples'"
40+
) from None
41+
42+
43+
get = _load_symbol("get")
44+
to_cell = _load_symbol("to_cell")
45+
show = _load_symbol("show")
46+
run = _load_symbol("run")
47+
shell_is_interactive = _load_symbol("shell_is_interactive")
File renamed without changes.

src/amuse_examples/Makefile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Building and installing packages
2+
develop-%:
3+
support/shared/uninstall.sh $*
4+
python -m pip install -e packages/$*
5+
6+
install-%:
7+
support/shared/uninstall.sh $*
8+
python -m pip install packages/$*
9+
10+
package-%:
11+
python3 -m pip install -vv --no-cache-dir --no-deps --no-build-isolation --prefix ${PREFIX} packages/$*
12+
13+
test-%:
14+
cd packages/$* && pytest
15+
16+
17+
# Cleaning up
18+
.PHONY: clean
19+
clean:
20+
21+
.PHONY: distclean
22+
distclean: clean
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def get_ipython():
1515
return None
1616

1717

18-
def get(example_name, prefix="amuse.examples"):
18+
def get(example_name, prefix="amuse_examples"):
1919
"""
2020
Retrieves an AMUSE example.
2121
"""
@@ -25,7 +25,7 @@ def get(example_name, prefix="amuse.examples"):
2525
return inspect.getsource(importlib.import_module(f"{prefix}{example_name}"))
2626

2727

28-
def to_cell(example_name, prefix="amuse.examples"):
28+
def to_cell(example_name, prefix="amuse_examples"):
2929
"""
3030
Creates a Jupyter cell from an AMUSE example.
3131
Works also for other modules, set prefix to None in that case.
@@ -36,7 +36,7 @@ def to_cell(example_name, prefix="amuse.examples"):
3636
shell.set_next_input(contents, replace=False)
3737

3838

39-
def show(example_name, prefix="amuse.examples"):
39+
def show(example_name, prefix="amuse_examples"):
4040
"""
4141
Prints the source code of an AMUSE example.
4242
"""
@@ -47,7 +47,7 @@ def run(example_name):
4747
"""
4848
Runs an AMUSE example.
4949
"""
50-
prefix = "amuse.examples."
50+
prefix = "amuse_examples."
5151
try:
5252
example = importlib.import_module(f"{prefix}{example_name}")
5353
except ImportError as exc:
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)