Skip to content

Commit 1a4460d

Browse files
committed
Merge current main into Langflow documentation update
Signed-off-by: zhifu gao <zhifu.gzf@alibaba-inc.com>
2 parents 4744ed7 + 5145ba3 commit 1a4460d

5 files changed

Lines changed: 168 additions & 5 deletions

File tree

‎.github/workflows/test-funasr-onnx-package.yml‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ on:
66
- ".github/workflows/test-funasr-onnx-package.yml"
77
- "runtime/python/onnxruntime/**"
88
- "tests/test_funasr_onnx_release.py"
9+
- "tests/test_funasr_onnx_installed.py"
910
push:
1011
branches:
1112
- main
1213
paths:
1314
- ".github/workflows/test-funasr-onnx-package.yml"
1415
- "runtime/python/onnxruntime/**"
1516
- "tests/test_funasr_onnx_release.py"
17+
- "tests/test_funasr_onnx_installed.py"
1618
workflow_dispatch:
1719

1820
permissions:
@@ -60,7 +62,7 @@ jobs:
6062
import importlib.util
6163
from importlib.metadata import requires, version
6264
63-
assert version("funasr-onnx") == "0.4.2"
65+
assert version("funasr-onnx") == "0.4.3"
6466
assert importlib.util.find_spec("torch") is None
6567
6668
requirements = requires("funasr-onnx") or []
@@ -76,10 +78,19 @@ jobs:
7678
)
7779
PY
7880
81+
- name: Verify installed wrapper error paths
82+
run: python tests/test_funasr_onnx_installed.py
83+
84+
- name: Verify source distribution error paths
85+
run: |
86+
python -m pip install --force-reinstall --no-deps dist/funasr-onnx/*.tar.gz
87+
python -m pip check
88+
python tests/test_funasr_onnx_installed.py
89+
7990
- name: Upload release candidate
8091
if: matrix.python-version == '3.12'
8192
uses: actions/upload-artifact@v7
8293
with:
83-
name: funasr-onnx-0.4.2
94+
name: funasr-onnx-0.4.3
8495
path: dist/funasr-onnx/*
8596
if-no-files-found: error

‎runtime/python/onnxruntime/README.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## Install `funasr-onnx`
44

5+
`funasr-onnx` is a separate distribution from `funasr`. Upgrading `funasr`
6+
does not update the installed ONNX wrappers. Check their versions separately
7+
with `python -m pip show funasr-onnx funasr`; use the source installation below
8+
when a required wrapper fix is newer than the published PyPI package.
9+
510
install from pip
611

712
```shell

‎runtime/python/onnxruntime/setup.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def get_readme():
1313

1414

1515
MODULE_NAME = "funasr_onnx"
16-
VERSION_NUM = "0.4.2"
16+
VERSION_NUM = "0.4.3"
1717

1818
setuptools.setup(
1919
name=MODULE_NAME,
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
"""Run against an installed wheel/sdist, outside the source package directory."""
2+
3+
import ast
4+
import builtins
5+
import contextlib
6+
import importlib.metadata
7+
import importlib.util
8+
import io
9+
import json
10+
from pathlib import Path
11+
import subprocess
12+
import sys
13+
import tempfile
14+
from types import SimpleNamespace
15+
import unittest
16+
from unittest.mock import patch
17+
18+
if importlib.util.find_spec('funasr_onnx') is None:
19+
raise unittest.SkipTest('Install the standalone funasr-onnx distribution first.')
20+
21+
import funasr_onnx
22+
from funasr_onnx.paraformer_online_bin import Paraformer as ParaformerOnline
23+
24+
25+
ENTRYPOINTS = (
26+
funasr_onnx.Paraformer,
27+
funasr_onnx.ContextualParaformer,
28+
funasr_onnx.SeacoParaformer,
29+
ParaformerOnline,
30+
funasr_onnx.Fsmn_vad,
31+
funasr_onnx.Fsmn_vad_online,
32+
funasr_onnx.CT_Transformer,
33+
funasr_onnx.CT_Transformer_VadRealtime,
34+
funasr_onnx.SenseVoiceSmall,
35+
)
36+
37+
38+
class InstalledOnnxPackageTest(unittest.TestCase):
39+
def test_installed_distribution_version_and_origin(self):
40+
distribution = importlib.metadata.distribution('funasr-onnx')
41+
self.assertEqual(distribution.version, '0.4.3')
42+
self.assertEqual(
43+
Path(funasr_onnx.__file__).resolve().parent,
44+
Path(distribution.locate_file('funasr_onnx')).resolve(),
45+
)
46+
47+
def test_installed_modules_have_no_string_exceptions(self):
48+
offenders = []
49+
for source in Path(funasr_onnx.__file__).parent.rglob('*.py'):
50+
for node in ast.walk(ast.parse(source.read_text(encoding='utf-8'))):
51+
if not isinstance(node, ast.Raise):
52+
continue
53+
literal = node.exc
54+
if (
55+
isinstance(literal, ast.Call)
56+
and isinstance(literal.func, ast.Attribute)
57+
and literal.func.attr == 'format'
58+
):
59+
literal = literal.func.value
60+
if isinstance(literal, ast.Constant) and isinstance(literal.value, str):
61+
offenders.append(f'{source.name}:{node.lineno}')
62+
self.assertEqual(offenders, [])
63+
64+
def check_export_import_error(self, error, expected_type, preserves_cause):
65+
original_import = builtins.__import__
66+
67+
def broken_export_import(name, *args, **kwargs):
68+
if name == 'funasr':
69+
raise error
70+
return original_import(name, *args, **kwargs)
71+
72+
# Only the optional exporter import is replaced; constructors are installed code.
73+
with tempfile.TemporaryDirectory() as model_dir:
74+
for entrypoint in ENTRYPOINTS:
75+
with self.subTest(entrypoint=entrypoint.__name__):
76+
error.__traceback__ = None
77+
with patch('builtins.__import__', side_effect=broken_export_import):
78+
with contextlib.redirect_stdout(io.StringIO()):
79+
with self.assertRaises(expected_type) as raised:
80+
entrypoint(model_dir)
81+
if preserves_cause:
82+
self.assertIs(raised.exception.__cause__, error)
83+
else:
84+
self.assertIs(raised.exception, error)
85+
86+
def test_missing_transitive_export_dependency_remains_visible(self):
87+
error = ModuleNotFoundError("No module named 'torchaudio'", name='torchaudio')
88+
self.check_export_import_error(error, ImportError, preserves_cause=True)
89+
90+
def test_unrelated_export_import_failure_is_not_misreported(self):
91+
error = RuntimeError('exporter initialization failed')
92+
self.check_export_import_error(error, RuntimeError, preserves_cause=False)
93+
94+
def test_failed_model_download_preserves_cause(self):
95+
original_import = builtins.__import__
96+
error = OSError('model download failed')
97+
98+
def failed_download(*args, **kwargs):
99+
raise error
100+
101+
def controlled_download_import(name, *args, **kwargs):
102+
if name == 'modelscope.hub.snapshot_download':
103+
return SimpleNamespace(snapshot_download=failed_download)
104+
return original_import(name, *args, **kwargs)
105+
106+
with tempfile.TemporaryDirectory() as directory:
107+
missing_model = str(Path(directory) / 'not-downloaded')
108+
for entrypoint in ENTRYPOINTS:
109+
with self.subTest(entrypoint=entrypoint.__name__):
110+
error.__traceback__ = None
111+
with patch('builtins.__import__', side_effect=controlled_download_import):
112+
with self.assertRaises(RuntimeError) as raised:
113+
entrypoint(missing_model)
114+
self.assertIs(raised.exception.__cause__, error)
115+
116+
def test_missing_onnxruntime_import_preserves_cause(self):
117+
script = '''
118+
import builtins
119+
import json
120+
original_import = builtins.__import__
121+
def broken_import(name, *args, **kwargs):
122+
if name == 'onnxruntime':
123+
raise ModuleNotFoundError("No module named 'onnxruntime'", name='onnxruntime')
124+
return original_import(name, *args, **kwargs)
125+
builtins.__import__ = broken_import
126+
try:
127+
import funasr_onnx
128+
except Exception as error:
129+
print(json.dumps({
130+
'type': type(error).__name__,
131+
'cause': type(error.__cause__).__name__,
132+
'missing': getattr(error.__cause__, 'name', None),
133+
}))
134+
else:
135+
print(json.dumps({'type': None}))
136+
'''
137+
result = subprocess.run(
138+
[sys.executable, '-c', script], capture_output=True, text=True, timeout=60,
139+
check=True,
140+
)
141+
self.assertEqual(json.loads(result.stdout.splitlines()[-1]), {
142+
'type': 'ImportError', 'cause': 'ModuleNotFoundError', 'missing': 'onnxruntime',
143+
})
144+
145+
146+
if __name__ == '__main__':
147+
unittest.main()

‎tests/test_funasr_onnx_release.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
ROOT = Path(__file__).resolve().parents[1]
88
PACKAGE_ROOT = ROOT / "runtime" / "python" / "onnxruntime"
99
SETUP_PATH = PACKAGE_ROOT / "setup.py"
10-
EXPECTED_VERSION = "0.4.2"
10+
EXPECTED_VERSION = "0.4.3"
1111
REQUIREMENT_NAME_PATTERN = re.compile(r"^\s*([A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?)")
1212

1313

@@ -44,7 +44,7 @@ def normalized_requirement_name(requirement):
4444

4545

4646
class FunASROnnxReleaseContractTest(unittest.TestCase):
47-
def test_release_version_is_0_4_2(self):
47+
def test_release_version_is_0_4_3(self):
4848
self.assertEqual(assigned_literal(read_setup_tree(), "VERSION_NUM"), EXPECTED_VERSION)
4949

5050
def test_runtime_dependencies_keep_onnx_install_torch_free(self):

0 commit comments

Comments
 (0)