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