Skip to content

Commit 7dcc3eb

Browse files
committed
#37 workaround to include the shared lib with the package
1 parent 3d09b7b commit 7dcc3eb

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

pywhispercpp/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1+
import os
2+
import ctypes
3+
from glob import glob
14

5+
lib_dir = os.path.join(os.path.dirname(__file__), 'lib/*')
6+
7+
for file in glob(lib_dir):
8+
ctypes.CDLL(os.path.join(os.path.dirname(__file__), 'lib', file))

setup.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import re
33
import subprocess
44
import sys
5+
from glob import glob
56
from pathlib import Path
67

78
from setuptools import Extension, setup, find_packages
@@ -122,6 +123,15 @@ def build_extension(self, ext: CMakeExtension) -> None:
122123
["cmake", "--build", ".", *build_args], cwd=build_temp, check=True
123124
)
124125

126+
def copy_extensions_to_source(self):
127+
super().copy_extensions_to_source()
128+
# Copy the shared library to the lib folder
129+
so_files = os.path.join(self.build_lib, '*.so')
130+
dll_files = os.path.join(self.build_lib, '*.dll')
131+
shared_libs = glob(so_files) + glob(dll_files)
132+
for file_path in shared_libs:
133+
filename = os.path.basename(file_path)
134+
self.copy_file(file_path, (Path.cwd() / 'pywhispercpp' / 'lib' / filename).resolve())
125135

126136
# read the contents of your README file
127137
this_directory = Path(__file__).parent
@@ -142,6 +152,8 @@ def build_extension(self, ext: CMakeExtension) -> None:
142152
python_requires=">=3.8",
143153
packages=find_packages('.'),
144154
package_dir={'': '.'},
155+
include_package_data=True,
156+
package_data={'': ['./lib/*']},
145157
long_description_content_type="text/markdown",
146158
license='MIT',
147159
entry_points={

0 commit comments

Comments
 (0)