Skip to content

Commit 7780bc3

Browse files
committed
update find boost_python for linux
1 parent 318e9a7 commit 7780bc3

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

setup.py

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
import glob
1111
import os
12+
import sys
13+
from ctypes.util import find_library
1214
from pathlib import Path
1315

1416
import numpy as np
@@ -17,24 +19,16 @@
1719
# Helper functions -----------------------------------------------------------
1820

1921

20-
def check_boost_libraries(lib_dir):
21-
pattern = "libboost_python*.*" if os.name != "nt" else "boost_python*.lib"
22-
found = list(lib_dir.glob(pattern))
23-
if not found:
24-
raise EnvironmentError(
25-
f"No boost_python libraries found in conda environment"
26-
f" at {lib_dir}. Please install libboost_python in your "
27-
f"conda environment."
28-
)
29-
30-
# convert into linker names
31-
lib = []
32-
for libpath in found:
33-
name = libpath.stem
34-
if name.startswith("lib"):
35-
name = name[3:]
36-
lib.append(name)
37-
return lib
22+
def get_boost_libraries():
23+
base_lib = "boost_python"
24+
major, minor = str(sys.version_info[0]), str(sys.version_info[1])
25+
tags = [f"{major}{minor}", major, ""]
26+
mttags = ["", "-mt"]
27+
candidates = [base_lib + tag for tag in tags for mt in mttags] + [base_lib]
28+
for lib in candidates:
29+
if find_library(lib):
30+
return [lib]
31+
raise RuntimeError("Cannot find a suitable Boost.Python library.")
3832

3933

4034
def get_env_config():
@@ -63,7 +57,7 @@ def create_extensions():
6357
else:
6458
objcryst_lib = "ObjCryst"
6559

66-
libraries = [objcryst_lib] + check_boost_libraries(Path(library_dirs[0]))
60+
libraries = [objcryst_lib] + get_boost_libraries()
6761
extra_objects = []
6862
extra_compile_args = []
6963
extra_link_args = []

0 commit comments

Comments
 (0)