PeriDEM 0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
peridem_env Namespace Reference

Functions

None ensure_peridem ()
 

Variables

list __all__ = ["REPO_ROOT", "ensure_peridem"]
 
 REPO_ROOT
 
tuple _BUILD_DIRS
 

Detailed Description

Make ``import peridem`` work from a build tree.

Examples import this first so they run straight from a checkout without
``pip install``. If peridem is already importable (installed, or PYTHONPATH is
set) this does nothing.

Function Documentation

◆ ensure_peridem()

None peridem_env.ensure_peridem ( )

Definition at line 32 of file peridem_env.py.

32def ensure_peridem() -> None:
33 try:
34 import peridem # noqa: F401
35
36 return
37 except ImportError:
38 pass
39 # The staged package under build/ carries the compiled _core; the source
40 # python/ directory does not, so it must never shadow it.
41 for rel in _BUILD_DIRS:
42 cand = REPO_ROOT / rel
43 if (cand / "peridem" / "__init__.py").is_file():
44 sys.path.insert(0, str(cand))
45 break
46 else:
47 sys.path.insert(0, str(REPO_ROOT / "python"))
48 try:
49 import peridem # noqa: F401
50 except ImportError as exc: # pragma: no cover - build guidance
51 raise SystemExit(
52 "cannot import peridem. Build the extension first:\n"
53 f" cmake -S {REPO_ROOT} -B {REPO_ROOT}/build -DEnable_Python=ON\n"
54 f" cmake --build {REPO_ROOT}/build --target peridem_core PeriDEM -j\n"
55 f"({exc})"
56 ) from exc
57
58

References ensure_peridem().

Referenced by ensure_peridem().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ __all__

list peridem_env.__all__ = ["REPO_ROOT", "ensure_peridem"]
private

Definition at line 21 of file peridem_env.py.

◆ _BUILD_DIRS

tuple peridem_env._BUILD_DIRS
protected
Initial value:
1= ("build/linux/python", "build/python", "build/Release/python",
2 "build/Debug/python")

Definition at line 28 of file peridem_env.py.

◆ REPO_ROOT

peridem_env.REPO_ROOT
Initial value:
1= next(
2 p for p in Path(__file__).resolve().parents
3 if (p / "python" / "peridem" / "__init__.py").is_file()
4)

Definition at line 23 of file peridem_env.py.