|
1 | 1 | import platform
|
2 | 2 | import ctypes
|
3 | 3 | import os
|
| 4 | +import warnings |
4 | 5 |
|
5 |
| -if platform.system() == 'Linux': |
6 |
| - dll = 'libcilreg.so' |
7 |
| -elif platform.system() == 'Windows': |
8 |
| - dll_file = 'cilreg.dll' |
9 |
| - dll = ctypes.util.find_library(dll_file) |
10 |
| -elif platform.system() == 'Darwin': |
11 |
| - dll = 'libcilreg.dylib' |
| 6 | +try: |
| 7 | + pre = {'Linux': 'lib', 'Windows': '', 'Darwin': 'lib'}[platform.system()] |
| 8 | +except KeyError: |
| 9 | + raise ValueError(f"unsupported platform: {platform.system()}") |
12 | 10 | else:
|
13 |
| - raise ValueError('Not supported platform, ', platform.system()) |
| 11 | + ext = {'Linux': '.so', 'Windows': '.dll', 'Darwin': '.dylib'}[platform.system()] |
14 | 12 |
|
15 |
| -cilreg = ctypes.cdll.LoadLibrary(os.path.join(os.path.dirname(__file__), dll)) |
| 13 | +_here = os.path.dirname(__file__) |
| 14 | +dll = f'{pre}cilreg{ext}' |
| 15 | +cilreg = ctypes.cdll.LoadLibrary(os.path.join(_here, dll)) |
16 | 16 |
|
| 17 | +gpudll = f'{pre}cilregcuda{ext}' |
17 | 18 | try:
|
18 |
| - if platform.system() == 'Linux': |
19 |
| - gpudll = 'libcilregcuda.so' |
20 |
| - elif platform.system() == 'Windows': |
21 |
| - gpudll_file = 'cilregcuda.dll' |
22 |
| - gpudll = ctypes.util.find_library(gpudll_file) |
23 |
| - elif platform.system() == 'Darwin': |
24 |
| - gpudll = 'libcilregcuda.dylib' |
25 |
| - else: |
26 |
| - raise ValueError('Not supported platform, ', platform.system()) |
27 |
| - |
28 |
| - cilregcuda = ctypes.cdll.LoadLibrary(os.path.join(os.path.dirname(__file__), gpudll)) |
29 |
| -except OSError as ose: |
30 |
| - print(ose) |
| 19 | + cilregcuda = ctypes.cdll.LoadLibrary(os.path.join(_here, gpudll)) |
| 20 | +except Exception as exc: |
| 21 | + warnings.warn(str(exc), ImportWarning, stacklevel=2) |
| 22 | + warnings.warn(f"Found: {os.listdir(_here)}", ImportWarning, stacklevel=2) |
31 | 23 | cilregcuda = None
|
0 commit comments