|
1 | 1 | "Python-MIP interface to the HiGHS solver." |
2 | 2 |
|
3 | | -import glob |
4 | 3 | import numbers |
5 | 4 | import logging |
6 | 5 | import os.path |
|
22 | 21 | libfile = os.environ[ENV_KEY] |
23 | 22 | logger.debug("Choosing HiGHS library {libfile} via {ENV_KEY}.") |
24 | 23 | else: |
25 | | - # try library shipped with highspy packaged |
26 | | - import highspy |
| 24 | + # Try library from highsbox, which is optional dependency. |
| 25 | + import highsbox |
| 26 | + root = highsbox.highs_dist_dir() |
27 | 27 |
|
28 | | - pkg_path = os.path.dirname(highspy.__file__) |
29 | | - |
30 | | - # need library matching operating system |
| 28 | + # Need library matching operating system. |
| 29 | + # Following: PyOptInterface/src/pyoptinterface/_src/highs.py |
31 | 30 | platform = sys.platform.lower() |
32 | 31 | if "linux" in platform: |
33 | | - patterns = ["highs_bindings.*.so", "_core.*.so"] |
| 32 | + libfile = os.path.join(root, "lib", "libhighs.so") |
34 | 33 | elif platform.startswith("win"): |
35 | | - patterns = ["highs_bindings.*.pyd", "_core.*.pyd"] |
| 34 | + libfile = os.path.join(root, "bin", "highs.dll") |
36 | 35 | elif any(platform.startswith(p) for p in ("darwin", "macos")): |
37 | | - patterns = ["highs_bindings.*.so", "_core.*.so"] |
| 36 | + libfile = os.path.join(root, "lib", "libhighs.dylib") |
38 | 37 | else: |
39 | 38 | raise NotImplementedError(f"{sys.platform} not supported!") |
40 | | - |
41 | | - # there should only be one match |
42 | | - matched_files = [] |
43 | | - for pattern in patterns: |
44 | | - matched_files.extend(glob.glob(os.path.join(pkg_path, pattern))) |
45 | | - if len(matched_files) != 1: |
46 | | - raise FileNotFoundError(f"Could not find HiGHS library in {pkg_path}.") |
47 | | - [libfile] = matched_files |
48 | | - logger.debug("Choosing HiGHS library {libfile} via highspy package.") |
| 39 | + logger.debug("Choosing HiGHS library {libfile} via highsbox package.") |
49 | 40 |
|
50 | 41 | highslib = ffi.dlopen(libfile) |
51 | 42 | has_highs = True |
|
0 commit comments