1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5
6 # build-system
7 cython,
8 numpy,
9 setuptools,
10
11 # tests
12 pytestCheckHook,
13 scipy,
14}:
15
16buildPythonPackage rec {
17 pname = "pesq";
18 version = "0.0.4";
19 pyproject = true;
20
21 src = fetchFromGitHub {
22 owner = "ludlows";
23 repo = "PESQ";
24 tag = "v${version}";
25 hash = "sha256-JuwZ+trFKGMetS3cC3pEQsV+wbj6+klFnC3THOd8bPE=";
26 };
27
28 postPatch =
29 # pythonRemoveDeps does not work for removing pytest-runner
30 ''
31 substituteInPlace setup.py \
32 --replace-fail ", 'pytest-runner'" ""
33 ''
34 # Flaky tests: numerical equality is not satisfied on ARM platforms
35 + ''
36 substituteInPlace tests/test_pesq.py \
37 --replace-fail \
38 "assert score == 1.6072081327438354" \
39 "assert abs(score - 1.6072081327438354) < 1e-5" \
40 --replace-fail \
41 "assert score == [1.6072081327438354]" \
42 "assert np.allclose(np.array(score), np.array([1.6072081327438354]))"
43 '';
44
45 build-system = [
46 cython
47 setuptools
48 numpy
49 ];
50
51 dependencies = [
52 numpy
53 ];
54
55 pythonImportsCheck = [
56 "pesq"
57 "pesq.cypesq"
58 ];
59
60 # Prevents importing the `pesq` module from the source files (which lack the cypesq extension)
61 preCheck = ''
62 rm -rf pesq
63 '';
64
65 nativeCheckInputs = [
66 pytestCheckHook
67 scipy
68 ];
69
70 meta = {
71 description = "PESQ (Perceptual Evaluation of Speech Quality) Wrapper for Python Users";
72 homepage = "https://github.com/ludlows/PESQ";
73 changelog = "https://github.com/ludlows/PESQ/releases/tag/v${version}";
74 license = lib.licenses.mit;
75 maintainers = with lib.maintainers; [ GaetanLepage ];
76 };
77}