1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6 fetchpatch,
7 cmake,
8 cython,
9 ninja,
10 scikit-build-core,
11 numpy,
12 hypothesis,
13 pandas,
14 pytestCheckHook,
15 rapidfuzz-cpp,
16 taskflow,
17}:
18
19buildPythonPackage rec {
20 pname = "rapidfuzz";
21 version = "3.13.0";
22 pyproject = true;
23
24 src = fetchFromGitHub {
25 owner = "maxbachmann";
26 repo = "RapidFuzz";
27 tag = "v${version}";
28 hash = "sha256-vwAqlTq4HIbmCL1HsHcgfVWETImxdqTsnenmX2RGXw8=";
29 };
30
31 patches = [
32 # https://github.com/rapidfuzz/RapidFuzz/pull/446
33 (fetchpatch {
34 name = "support-taskflow-3.10.0.patch";
35 url = "https://github.com/rapidfuzz/RapidFuzz/commit/bba3281cc61ecc4ab4affe5d2d50389a4f6d7556.patch";
36 hash = "sha256-kAS6xsPY7eUTfKO+EAOW8bktY4cApvLEpRMciJEsPgk=";
37 })
38 ];
39
40 postPatch = ''
41 substituteInPlace pyproject.toml \
42 --replace-fail "Cython >=3.0.12, <3.1.0" Cython
43 '';
44
45 build-system = [
46 cmake
47 cython
48 ninja
49 scikit-build-core
50 ];
51
52 dontUseCmakeConfigure = true;
53
54 buildInputs = [
55 rapidfuzz-cpp
56 taskflow
57 ];
58
59 env.RAPIDFUZZ_BUILD_EXTENSION = 1;
60
61 preBuild = lib.optionalString (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86_64) ''
62 export CMAKE_ARGS="-DCMAKE_CXX_COMPILER_AR=$AR -DCMAKE_CXX_COMPILER_RANLIB=$RANLIB"
63 '';
64
65 optional-dependencies = {
66 all = [ numpy ];
67 };
68
69 preCheck = ''
70 export RAPIDFUZZ_IMPLEMENTATION=cpp
71 '';
72
73 nativeCheckInputs = [
74 hypothesis
75 pandas
76 pytestCheckHook
77 ];
78
79 disabledTests = lib.optionals (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86_64) [
80 # segfaults
81 "test_cdist"
82 ];
83
84 pythonImportsCheck = [
85 "rapidfuzz.distance"
86 "rapidfuzz.fuzz"
87 "rapidfuzz.process"
88 "rapidfuzz.utils"
89 ];
90
91 meta = {
92 description = "Rapid fuzzy string matching";
93 homepage = "https://github.com/maxbachmann/RapidFuzz";
94 changelog = "https://github.com/maxbachmann/RapidFuzz/blob/${src.tag}/CHANGELOG.rst";
95 license = lib.licenses.mit;
96 maintainers = with lib.maintainers; [ dotlambda ];
97 };
98}