Skip to content

Commit 2af7956

Browse files
new release
1 parent 7005171 commit 2af7956

File tree

10 files changed

+89
-4
lines changed

10 files changed

+89
-4
lines changed

python/Agent/testenv/lib/python3.12/site-packages/ctranslate2-4.5.0.dist-info/RECORD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ ctranslate2-4.5.0.dist-info/METADATA,sha256=BYImJX7omPH9-0tmj4NYSut9E4dWOlbr2wn2
1010
ctranslate2-4.5.0.dist-info/RECORD,,
1111
ctranslate2-4.5.0.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
1212
ctranslate2-4.5.0.dist-info/WHEEL,sha256=czuU-a4AygVBwu0_0kHdwSAcpGkvzCzftoVV6XyA-TE,109
13-
ctranslate2-4.5.0.dist-info/direct_url.json,sha256=TY6L3YEVXFrbzC6i_wFIk4pQhyi05ErvK3MyHSKPGwQ,94
13+
ctranslate2-4.5.0.dist-info/direct_url.json,sha256=hEdd9jndL9u3XpfJYYNQd4F2HDSkKLxw0j28Yv48dpY,326
1414
ctranslate2-4.5.0.dist-info/entry_points.txt,sha256=ZHkojut_TmVRHl0bJIGm2b9wqr98GAJqxN9rlJtQshs,466
1515
ctranslate2-4.5.0.dist-info/top_level.txt,sha256=1hUaWzcFIuSo2BAIUHFA3Osgsu6S1giq0y6Rosv8HOQ,12
16-
ctranslate2/__init__.py,sha256=o041z4XnNtnVF-CZoV-vUakHRcFBOfiqOtQDOJtHdNU,1452
16+
ctranslate2/__init__.py,sha256=gHcQKVc-9fvgoUse8MDvZU3MKEh_LlR-jArm-iCuXY0,1896
1717
ctranslate2/__pycache__/__init__.cpython-312.pyc,,
1818
ctranslate2/__pycache__/extensions.cpython-312.pyc,,
1919
ctranslate2/__pycache__/logging.cpython-312.pyc,,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"dir_info": {}, "url": "file:///Users/christophbackhaus/Documents/GitHub/CTranslate2/python"}
1+
{"archive_info": {"hash": "sha256=f17011096fc9e17ad06e6ad2d701ca8bca4bf9e88af7a1828db7944ae744e9f6", "hashes": {"sha256": "f17011096fc9e17ad06e6ad2d701ca8bca4bf9e88af7a1828db7944ae744e9f6"}}, "url": "file:///Users/christophbackhaus/Documents/GitHub/CTranslate2/python/dist/ctranslate2-4.5.0-cp312-cp312-macosx_14_0_arm64.whl"}

python/Agent/testenv/lib/python3.12/site-packages/ctranslate2/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@
1717
for library in glob.glob(os.path.join(package_dir, "*.dll")):
1818
ctypes.CDLL(library)
1919

20+
import sys
21+
import os
22+
import glob
23+
import ctypes
24+
from pathlib import Path
25+
26+
if sys.platform == "darwin":
27+
# Ensure the .dylib is loaded from the same directory as the .so
28+
package_dir = Path(__file__).parent.absolute()
29+
for dylib_path in package_dir.glob("libctranslate2*.dylib"):
30+
try:
31+
ctypes.CDLL(str(dylib_path))
32+
except Exception as e:
33+
pass # fallback: let import error happen if truly missing
34+
2035
try:
2136
from ctranslate2._ext import (
2237
AsyncGenerationResult,

python/ctranslate2/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@
1717
for library in glob.glob(os.path.join(package_dir, "*.dll")):
1818
ctypes.CDLL(library)
1919

20+
import sys
21+
import os
22+
import glob
23+
import ctypes
24+
from pathlib import Path
25+
26+
if sys.platform == "darwin":
27+
# Ensure the .dylib is loaded from the same directory as the .so
28+
package_dir = Path(__file__).parent.absolute()
29+
for dylib_path in package_dir.glob("libctranslate2*.dylib"):
30+
try:
31+
ctypes.CDLL(str(dylib_path))
32+
except Exception as e:
33+
pass # fallback: let import error happen if truly missing
34+
2035
try:
2136
from ctranslate2._ext import (
2237
AsyncGenerationResult,
0 Bytes
Binary file not shown.
2.07 MB
Binary file not shown.
2.07 MB
Binary file not shown.
2.07 MB
Binary file not shown.

python/setup.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,36 @@ def build_cpp_lib():
4545
subprocess.check_call(["cmake", "--build", str(build_dir), "-j", str(os.cpu_count())])
4646
subprocess.check_call(["cmake", "--install", str(build_dir)])
4747

48+
import shutil
49+
import glob
50+
4851
class CustomBuildExt(build_ext):
49-
"""Custom build command that builds the C++ library first."""
52+
"""Custom build command that builds the C++ library first and copies the dylib into the package."""
5053
def run(self):
5154
build_cpp_lib()
55+
# Find and copy the libctranslate2*.dylib into ctranslate2/
56+
root_dir = Path(__file__).parent.parent.absolute()
57+
dylib_candidates = list(root_dir.glob('python/Agent/testenv/lib/libctranslate2*.dylib'))
58+
target_dir = Path(__file__).parent / 'ctranslate2'
59+
target_dir.mkdir(exist_ok=True)
60+
for dylib_path in dylib_candidates:
61+
shutil.copy2(dylib_path, target_dir)
62+
# Fix install_name of the .so to use @loader_path for the dylib
63+
if sys.platform == "darwin":
64+
try:
65+
so_files = list(target_dir.glob("_ext.cpython-*.so"))
66+
for so_path in so_files:
67+
for dylib_path in target_dir.glob("libctranslate2*.dylib"):
68+
import subprocess
69+
subprocess.run([
70+
"install_name_tool",
71+
"-change",
72+
f"@rpath/{dylib_path.name}",
73+
f"@loader_path/{dylib_path.name}",
74+
str(so_path)
75+
], check=True)
76+
except Exception as e:
77+
print(f"[WARNING] Failed to patch install_name for .so: {e}")
5278
super().run()
5379

5480
# Define the extension module

python/tests/test_wheel_native.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import os
2+
import sys
3+
import glob
4+
import ctypes
5+
from pathlib import Path
6+
import importlib
7+
import pytest
8+
9+
def test_dylib_present():
10+
# The .dylib must be present in the installed package directory
11+
import ctranslate2
12+
package_dir = Path(ctranslate2.__file__).parent
13+
dylibs = list(package_dir.glob("libctranslate2*.dylib"))
14+
assert dylibs, f"No libctranslate2*.dylib found in {package_dir}"
15+
16+
def test_import_and_device():
17+
import ctranslate2
18+
# Should import without error and have a version
19+
assert hasattr(ctranslate2, "__version__")
20+
# Try to use MPS device if available
21+
try:
22+
from faster_whisper import WhisperModel
23+
model = WhisperModel("tiny", device="mps", compute_type="float16")
24+
assert model is not None
25+
assert model.device == "mps"
26+
except ImportError:
27+
pytest.skip("faster_whisper not installed, skipping device test")
28+
except Exception as e:
29+
pytest.skip(f"MPS device test skipped due to: {e}")

0 commit comments

Comments
 (0)