Skip to content

Commit

Permalink
#37 workaround to include the shared lib with the package
Browse files Browse the repository at this point in the history
  • Loading branch information
abdeladim-s committed Jun 1, 2024
1 parent 3d09b7b commit 7dcc3eb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pywhispercpp/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
import os
import ctypes
from glob import glob

lib_dir = os.path.join(os.path.dirname(__file__), 'lib/*')

for file in glob(lib_dir):
ctypes.CDLL(os.path.join(os.path.dirname(__file__), 'lib', file))
12 changes: 12 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import re
import subprocess
import sys
from glob import glob
from pathlib import Path

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

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

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

0 comments on commit 7dcc3eb

Please sign in to comment.