-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy path__init__.py
More file actions
57 lines (45 loc) · 1.37 KB
/
Copy path__init__.py
File metadata and controls
57 lines (45 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""FIFE Python bindings."""
import ctypes
import importlib
import os
from glob import glob
from typing import TYPE_CHECKING, Any, cast
def _candidate_library_dirs(package_dir):
candidates = [package_dir, os.path.dirname(package_dir)]
current = package_dir
while True:
parent = os.path.dirname(current)
if parent == current:
break
candidates.append(
os.path.join(parent, "out", "fife-dependencies", "install", "lib")
)
current = parent
return candidates
def _preload_optional_gui_backend():
if os.name != "posix":
return
package_dir = os.path.dirname(__file__)
for library_dir in _candidate_library_dirs(package_dir):
for library_path in sorted(
glob(os.path.join(library_dir, "libfifechan_sdl3.so*"))
):
try:
ctypes.CDLL(library_path, mode=ctypes.RTLD_GLOBAL)
return
except OSError:
continue
_preload_optional_gui_backend()
if TYPE_CHECKING:
from . import fife as fife
else:
fife = importlib.import_module(".fife", __name__)
if TYPE_CHECKING:
from . import fifechan as _fifechan
else:
try:
_fifechan = importlib.import_module(".fifechan", __name__)
except ImportError:
_fifechan = None
fifechan: Any = cast(Any, _fifechan)
__all__ = ["fife", "fifechan"]