|
1 | 1 | from PyInstaller.utils.hooks import collect_data_files, get_package_paths
|
2 | 2 | import os
|
| 3 | +import re |
3 | 4 |
|
4 |
| -hiddenimports=['_cffi_backend'] |
| 5 | +hiddenimports = ['_cffi_backend'] |
5 | 6 |
|
6 | 7 | # Get the package path
|
7 | 8 | package_path = get_package_paths('coincurve')[0]
|
8 | 9 |
|
9 | 10 | # Collect data files
|
10 | 11 | datas = collect_data_files('coincurve')
|
11 | 12 |
|
12 |
| -# Append the additional .dll or .so file |
13 |
| -if os.name == 'nt': # Windows |
14 |
| - dll_path = os.path.join(package_path, 'coincurve', 'libsecp256k1.dll') |
15 |
| - datas.append((dll_path, 'coincurve')) |
16 |
| -elif os.name == 'posix': # Linux/Mac |
17 |
| - so_paths =[ |
18 |
| - os.path.join(package_path, 'coincurve', 'libsecp256k1.so'), |
19 |
| - os.path.join(package_path, 'coincurve', '_libsecp256k1.cpython-311-x86_64-linux-gnu.so') |
20 |
| - ] |
21 |
| - so_path = None |
22 |
| - for p in so_paths: |
23 |
| - if os.path.exists(p): |
24 |
| - so_path = p |
25 |
| - assert so_path, f"can't find coincurve lib, look in {package_path} and then modify this hook" |
26 |
| - datas.append((so_path, 'coincurve')) |
| 13 | +# Regular expression pattern for libsecp256k1 |
| 14 | +libsecp256k1_pattern = re.compile(r'(libsecp256k1|_libsecp256k1).*\.(dll|so)') |
27 | 15 |
|
| 16 | +# Search for libsecp256k1 file within the 'coincurve' folder |
| 17 | +coincurve_path = os.path.join(package_path, 'coincurve') |
| 18 | +libsecp256k1_path = None |
| 19 | +for root, _, files in os.walk(coincurve_path): |
| 20 | + for file in files: |
| 21 | + if libsecp256k1_pattern.search(file): |
| 22 | + libsecp256k1_path = os.path.join(root, file) |
| 23 | + datas.append((libsecp256k1_path, 'coincurve')) |
| 24 | + break |
| 25 | + |
| 26 | + assert libsecp256k1_path, f"can't find coincurve libsecp256k1, look in {coincurve_path} and then modify this hook" |
0 commit comments