PeriDEM
0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
peridem_env.py
Go to the documentation of this file.
1
# -------------------------------------------
2
# Copyright (c) 2021 - 2026 Prashant K. Jha
3
# -------------------------------------------
4
# PeriDEM https://github.com/prashjha/PeriDEM
5
#
6
# Distributed under the Boost Software License, Version 1.0. (See accompanying
7
# file LICENSE)
8
9
"""Make ``import peridem`` work from a build tree.
10
11
Examples import this first so they run straight from a checkout without
12
``pip install``. If peridem is already importable (installed, or PYTHONPATH is
13
set) this does nothing.
14
"""
15
16
from
__future__
import
annotations
17
18
import
sys
19
from
pathlib
import
Path
20
21
__all__ = [
"REPO_ROOT"
,
"ensure_peridem"
]
22
23
REPO_ROOT = next(
24
p
for
p
in
Path(__file__).resolve().parents
25
if
(p /
"python"
/
"peridem"
/
"__init__.py"
).is_file()
26
)
27
28
_BUILD_DIRS = (
"build/linux/python"
,
"build/python"
,
"build/Release/python"
,
29
"build/Debug/python"
)
30
31
32
def
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
59
ensure_peridem
()
peridem_env.ensure_peridem
None ensure_peridem()
Definition
peridem_env.py:32
examples
peridem_env.py
Generated by
1.9.8