|
20 | 20 |
|
21 | 21 |
|
22 | 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] |
| 23 | + # the names we'll search for |
| 24 | + major, minor = sys.version_info[:2] |
| 25 | + candidates = [ |
| 26 | + f"boost_python{major}{minor}", |
| 27 | + f"boost_python{major}", |
| 28 | + "boost_python", |
| 29 | + ] |
| 30 | + |
| 31 | + conda_prefix = os.environ.get("CONDA_PREFIX") |
| 32 | + if conda_prefix: |
| 33 | + libdir = os.path.join(conda_prefix, "lib") |
| 34 | + for name in candidates: |
| 35 | + so = f"lib{name}.so" |
| 36 | + if os.path.isfile(os.path.join(libdir, so)): |
| 37 | + # return the plain "boost_python311" etc (no "lib" prefix or ".so") |
| 38 | + return [name] |
| 39 | + |
| 40 | + # fallback to ldconfig |
| 41 | + for name in candidates: |
| 42 | + found = find_library(name) |
| 43 | + if found: |
| 44 | + # find_library may return "libboost_python3.so.1.74.0" etc |
| 45 | + # strip off lib*.so.* if you like, or just return name |
| 46 | + return [name] |
| 47 | + |
31 | 48 | raise RuntimeError("Cannot find a suitable Boost.Python library.") |
32 | 49 |
|
33 | 50 |
|
@@ -92,10 +109,11 @@ def create_extensions(): |
92 | 109 | return [ext] |
93 | 110 |
|
94 | 111 |
|
95 | | -setup_args = dict( |
96 | | - ext_modules=[], |
97 | | -) |
| 112 | +def ext_modules(): |
| 113 | + if set(sys.argv) & {"build_ext", "bdist_wheel", "install"}: |
| 114 | + return create_extensions() |
| 115 | + return [] |
| 116 | + |
98 | 117 |
|
99 | 118 | if __name__ == "__main__": |
100 | | - setup_args["ext_modules"] = create_extensions() |
101 | | - setup(**setup_args) |
| 119 | + setup(ext_modules=ext_modules()) |
0 commit comments