Skip to content

Commit c26d23d

Browse files
committed
capi: allow editable installs
By also inspecting site-packages when importing the shared library, editable installs should be better supported. Typically, the shared library is not installed in the source directory during an editable install.
1 parent 832b537 commit c26d23d

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/pbk/capi/bindings.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,21 @@
77
#
88
import ctypes
99
import ctypes.util
10+
import site
11+
from importlib import resources
1012
from pathlib import Path
1113

1214

1315
def _find_bitcoinkernel_lib():
14-
# Check relative ../_libs/ directory
15-
script_dir = Path(__file__).parent
16-
if (matches := list((script_dir.parent / "_libs").glob("*bitcoinkernel*"))):
16+
resources_paths = [resources.files("pbk")]
17+
# Adding site packages makes this work in editable mode with scikit-build-core
18+
site_packages_paths = [Path(p) / "pbk" for p in site.getsitepackages()]
19+
for pkg_path in [*resources_paths, *site_packages_paths]:
20+
matches = list((pkg_path / "_libs").glob('*bitcoinkernel*'))
1721
if len(matches) == 1:
1822
return str(matches[0])
19-
raise RuntimeError(f"Found multiple libbitcoinkernel candidates: {matches}")
20-
23+
if matches:
24+
raise RuntimeError(f"Found multiple libbitcoinkernel candidates: {matches}")
2125
raise RuntimeError(
2226
"Could not find libbitcoinkernel. Please re-run `pip install`."
2327
)

0 commit comments

Comments
 (0)