|
58 | 58 | if _repo_build_pkg_dir.is_dir(): |
59 | 59 | __path__.append(str(_repo_build_pkg_dir)) |
60 | 60 |
|
| 61 | +from ._backend import get_capi_module, get_pybind_module # noqa: E402 |
| 62 | + |
| 63 | + |
| 64 | +def _get_version_source() -> type: |
| 65 | + backend = os.getenv("LBUG_PYTHON_BACKEND", "auto").strip().lower() |
| 66 | + if backend != "capi": |
| 67 | + pybind_module = get_pybind_module() |
| 68 | + if pybind_module is not None: |
| 69 | + return pybind_module.Database |
| 70 | + return get_capi_module().Database |
| 71 | + |
| 72 | + |
| 73 | +_version_source = _get_version_source() |
| 74 | +# Resolve version info before restoring dlopen flags so a pybind import, when |
| 75 | +# selected, happens under RTLD_GLOBAL and its symbols remain visible to |
| 76 | +# subsequently loaded extensions such as json. |
| 77 | +version = __version__ = _version_source.get_version() |
| 78 | +storage_version = _version_source.get_storage_version() |
| 79 | + |
61 | 80 | from .async_connection import AsyncConnection # noqa: E402 |
62 | 81 | from .connection import Connection # noqa: E402 |
63 | 82 | from .database import Database # noqa: E402 |
|
67 | 86 |
|
68 | 87 |
|
69 | 88 | def __getattr__(name: str) -> str | int: |
70 | | - if name in ("version", "__version__"): |
71 | | - return Database.get_version() |
72 | | - elif name == "storage_version": |
73 | | - return Database.get_storage_version() |
74 | | - else: |
75 | | - msg = f"module {__name__!r} has no attribute {name!r}" |
76 | | - raise AttributeError(msg) |
| 89 | + msg = f"module {__name__!r} has no attribute {name!r}" |
| 90 | + raise AttributeError(msg) |
77 | 91 |
|
78 | 92 |
|
79 | 93 | # Restore the original dlopen flags |
|
0 commit comments