Skip to content

Commit a5fd147

Browse files
committed
Fix bug in PyPI
1 parent 964f155 commit a5fd147

File tree

3 files changed

+102
-73
lines changed

3 files changed

+102
-73
lines changed

MANIFEST.in

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# Copyright © 2025 Agora
3+
# This file is part of TEN Framework, an open source project.
4+
# Licensed under the Apache License, Version 2.0, with certain conditions.
5+
# Refer to the "LICENSE" file in the root directory for more information.
6+
#
7+
8+
# Include license and documentation
9+
include LICENSE
10+
include NOTICES
11+
include README.md
12+
13+
# Include Python interface
14+
include include/ten_vad.py
15+
16+
# Include library files needed for building
17+
include lib/Linux/x64/libten_vad.so
18+
include lib/Windows/x64/ten_vad.dll
19+
include lib/Windows/x86/ten_vad.dll
20+
include lib/macOS/ten_vad.framework/Versions/A/ten_vad
21+
22+
# Exclude unnecessary files
23+
prune testset
24+
prune examples
25+
prune examples_onnx
26+
prune src

include/ten_vad.py

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,62 +13,63 @@ class TenVad:
1313
def __init__(self, hop_size: int = 256, threshold: float = 0.5):
1414
self.hop_size = hop_size
1515
self.threshold = threshold
16+
17+
# Get the directory where this module is installed
18+
module_dir = os.path.dirname(os.path.abspath(__file__))
19+
1620
if platform.system() == "Linux" and platform.machine() == "x86_64":
17-
git_path = os.path.join(
18-
os.path.dirname(os.path.relpath(__file__)),
19-
"../lib/Linux/x64/libten_vad.so"
20-
)
21+
# Try git repo structure first
22+
git_path = os.path.join(module_dir, "../lib/Linux/x64/libten_vad.so")
23+
# Try installed package structure (lib directory is inside the package)
24+
pip_path = os.path.join(module_dir, "lib/Linux/x64/libten_vad.so")
25+
2126
if os.path.exists(git_path):
2227
self.vad_library = CDLL(git_path)
23-
else:
24-
pip_path = os.path.join(
25-
os.path.dirname(os.path.relpath(__file__)),
26-
"./ten_vad_library/libten_vad.so"
27-
)
28+
elif os.path.exists(pip_path):
2829
self.vad_library = CDLL(pip_path)
30+
else:
31+
raise FileNotFoundError("Cannot find libten_vad.so at {} or {}".format(git_path, pip_path))
2932

3033
elif platform.system() == "Darwin":
31-
git_path = os.path.join(
32-
os.path.dirname(os.path.relpath(__file__)),
33-
"../lib/macOS/ten_vad.framework/Versions/A/ten_vad"
34-
)
34+
# Try git repo structure first
35+
git_path = os.path.join(module_dir, "../lib/macOS/ten_vad.framework/Versions/A/ten_vad")
36+
# Try installed package structure
37+
pip_path = os.path.join(module_dir, "lib/macOS/ten_vad.framework/Versions/A/ten_vad")
38+
3539
if os.path.exists(git_path):
3640
self.vad_library = CDLL(git_path)
37-
else:
38-
pip_path = os.path.join(
39-
os.path.dirname(os.path.relpath(__file__)),
40-
"./ten_vad_library/libten_vad"
41-
)
41+
elif os.path.exists(pip_path):
4242
self.vad_library = CDLL(pip_path)
43+
else:
44+
raise FileNotFoundError("Cannot find libten_vad at {} or {}".format(git_path, pip_path))
45+
4346
elif platform.system().upper() == 'WINDOWS':
4447
if platform.machine().upper() in ['X64', 'X86_64', 'AMD64']:
45-
git_path = os.path.join(
46-
os.path.dirname(os.path.realpath(__file__)),
47-
"../lib/Windows/x64/ten_vad.dll"
48-
)
48+
# Try git repo structure first
49+
git_path = os.path.join(module_dir, "../lib/Windows/x64/ten_vad.dll")
50+
# Try installed package structure
51+
pip_path = os.path.join(module_dir, "lib/Windows/x64/ten_vad.dll")
52+
4953
if os.path.exists(git_path):
5054
self.vad_library = CDLL(git_path)
51-
else:
52-
pip_path = os.path.join(
53-
os.path.dirname(os.path.realpath(__file__)),
54-
"./ten_vad_library/ten_vad.dll"
55-
)
55+
elif os.path.exists(pip_path):
5656
self.vad_library = CDLL(pip_path)
57+
else:
58+
raise FileNotFoundError("Cannot find ten_vad.dll at {} or {}".format(git_path, pip_path))
5759
else:
58-
git_path = os.path.join(
59-
os.path.dirname(os.path.realpath(__file__)),
60-
"../lib/Windows/x86/ten_vad.dll"
61-
)
60+
# Try git repo structure first
61+
git_path = os.path.join(module_dir, "../lib/Windows/x86/ten_vad.dll")
62+
# Try installed package structure
63+
pip_path = os.path.join(module_dir, "lib/Windows/x86/ten_vad.dll")
64+
6265
if os.path.exists(git_path):
6366
self.vad_library = CDLL(git_path)
64-
else:
65-
pip_path = os.path.join(
66-
os.path.dirname(os.path.realpath(__file__)),
67-
"./ten_vad_library/ten_vad.dll"
68-
)
67+
elif os.path.exists(pip_path):
6968
self.vad_library = CDLL(pip_path)
69+
else:
70+
raise FileNotFoundError("Cannot find ten_vad.dll at {} or {}".format(git_path, pip_path))
7071
else:
71-
raise NotImplementedError(f"Unsupported platform: {platform.system()} {platform.machine()}")
72+
raise NotImplementedError("Unsupported platform: {} {}".format(platform.system(), platform.machine()))
7273
self.vad_handler = c_void_p(0)
7374
self.out_probability = c_float()
7475
self.out_flags = c_int32()
@@ -116,9 +117,7 @@ def get_input_data(self, audio_data: np.ndarray):
116117
assert (
117118
len(audio_data.shape) == 1
118119
and audio_data.shape[0] == self.hop_size
119-
), "[TEN VAD]: audio data shape should be [%d]" % (
120-
self.hop_size
121-
)
120+
), "[TEN VAD]: audio data shape should be [{}]".format(self.hop_size)
122121
assert (
123122
type(audio_data[0]) == np.int16
124123
), "[TEN VAD]: audio data type error, must be int16"

setup.py

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,46 @@
55
# Refer to the "LICENSE" file in the root directory for more information.
66
#
77
from setuptools import setup
8-
import os, shutil, platform
9-
from setuptools.command.install import install
10-
11-
class custom_install_command(install):
12-
def run(self):
13-
install.run(self)
14-
target_dir = os.path.join(self.install_lib, "ten_vad_library")
15-
os.makedirs(target_dir, exist_ok=True)
16-
17-
if platform.system() == "Linux" and platform.machine() == "x86_64":
18-
shutil.copy("lib/Linux/x64/libten_vad.so", target_dir)
19-
print(f"Linux x64 library installed to: {target_dir}")
20-
elif platform.system() == "Darwin":
21-
shutil.copy("lib/macOS/ten_vad.framework/Versions/A/ten_vad",
22-
os.path.join(target_dir, "libten_vad"))
23-
print(f"macOS library installed to: {target_dir}")
24-
elif platform.system().upper() == 'WINDOWS':
25-
if platform.machine().upper() in ['X64', 'X86_64', 'AMD64']:
26-
shutil.copy("lib/Windows/x64/ten_vad.dll",
27-
os.path.join(target_dir, "ten_vad.dll"))
28-
print(f"Windows x64 library installed to: {target_dir}")
29-
else:
30-
shutil.copy("lib/Windows/x86/ten_vad.dll",
31-
os.path.join(target_dir, "ten_vad.dll"))
32-
print(f"Windows x86 library installed to: {target_dir}")
33-
else:
34-
raise NotImplementedError(f"Unsupported platform: {platform.system()} {platform.machine()}")
8+
import os, shutil
359

3610
root_dir = os.path.dirname(os.path.abspath(__file__))
37-
shutil.copy(f"{root_dir}/include/ten_vad.py", f"{root_dir}/ten_vad.py")
11+
12+
# Create a ten_vad package directory structure
13+
package_dir = os.path.join(root_dir, "ten_vad")
14+
os.makedirs(package_dir, exist_ok=True)
15+
16+
# Copy the Python interface as __init__.py
17+
shutil.copy("{}/include/ten_vad.py".format(root_dir), "{}/__init__.py".format(package_dir))
18+
19+
# Copy entire lib directory structure to package, excluding unwanted platforms
20+
lib_src = os.path.join(root_dir, "lib")
21+
lib_dst = os.path.join(package_dir, "lib")
22+
if os.path.exists(lib_dst):
23+
shutil.rmtree(lib_dst)
24+
shutil.copytree(lib_src, lib_dst,
25+
ignore=shutil.ignore_patterns('Android', 'iOS', 'Web', '*.lib'))
26+
27+
# Read the README for long description
28+
with open(os.path.join(root_dir, "README.md"), "r", encoding="utf-8") as f:
29+
long_description = f.read()
30+
3831
setup(
3932
name="ten_vad",
40-
version="1.0",
41-
py_modules=["ten_vad"],
42-
cmdclass={
43-
"install": custom_install_command,
33+
version="1.0.6.6",
34+
packages=["ten_vad"],
35+
package_data={
36+
"ten_vad": [
37+
"lib/Linux/x64/*.so",
38+
"lib/Windows/x64/*.dll",
39+
"lib/Windows/x86/*.dll",
40+
"lib/macOS/ten_vad.framework/Versions/A/ten_vad",
41+
],
4442
},
43+
include_package_data=True,
44+
long_description=long_description,
45+
long_description_content_type="text/markdown",
4546
)
46-
os.remove(f"{root_dir}/ten_vad.py")
47+
48+
# Cleanup temporary package directory
49+
if os.path.exists(package_dir):
50+
shutil.rmtree(package_dir)

0 commit comments

Comments
 (0)