1{ 2 lib, 3 stdenv, 4 fetchFromGitHub, 5 fetchpatch, 6 buildPythonPackage, 7 rustPlatform, 8 pkg-config, 9 openssl, 10 publicsuffix-list, 11 pythonOlder, 12 libiconv, 13 pytestCheckHook, 14 toml, 15}: 16 17buildPythonPackage rec { 18 pname = "adblock"; 19 version = "0.6.0"; 20 format = "pyproject"; 21 22 disabled = pythonOlder "3.7"; 23 24 # Pypi only has binary releases 25 src = fetchFromGitHub { 26 owner = "ArniDagur"; 27 repo = "python-adblock"; 28 tag = version; 29 hash = "sha256-5g5xdUzH/RTVwu4Vfb5Cb1t0ruG0EXgiXjrogD/+JCU="; 30 }; 31 32 patches = [ 33 # https://github.com/ArniDagur/python-adblock/pull/91 34 (fetchpatch { 35 name = "pep-621-compat.patch"; 36 url = "https://github.com/ArniDagur/python-adblock/commit/2a8716e0723b60390f0aefd0e05f40ba598ac73f.patch"; 37 hash = "sha256-n9+LDs0no66OdNZxw3aU57ngWrAbmm6hx4qIuxXoatM="; 38 }) 39 ]; 40 41 postPatch = '' 42 substituteInPlace pyproject.toml \ 43 --replace "0.0.0" "${version}" 44 ''; 45 46 cargoDeps = rustPlatform.fetchCargoVendor { 47 inherit pname version src; 48 hash = "sha256-fetJX6HQxRZ/Az7rJeU9S+s8ttgNPnJEvTLfzGt4xjk="; 49 }; 50 51 nativeBuildInputs = [ 52 pkg-config 53 ] 54 ++ (with rustPlatform; [ 55 cargoSetupHook 56 maturinBuildHook 57 ]); 58 59 buildInputs = [ 60 openssl 61 ] 62 ++ lib.optionals stdenv.hostPlatform.isDarwin [ 63 libiconv 64 ]; 65 66 PSL_PATH = "${publicsuffix-list}/share/publicsuffix/public_suffix_list.dat"; 67 68 nativeCheckInputs = [ 69 pytestCheckHook 70 toml 71 ]; 72 73 preCheck = '' 74 # import from $out instead 75 rm -r adblock 76 ''; 77 78 disabledTestPaths = [ 79 # relies on directory removed above 80 "tests/test_typestubs.py" 81 ]; 82 83 pythonImportsCheck = [ 84 "adblock" 85 "adblock.adblock" 86 ]; 87 88 meta = with lib; { 89 description = "Python wrapper for Brave's adblocking library"; 90 homepage = "https://github.com/ArniDagur/python-adblock/"; 91 changelog = "https://github.com/ArniDagur/python-adblock/blob/${version}/CHANGELOG.md"; 92 maintainers = with maintainers; [ dotlambda ]; 93 license = with licenses; [ 94 asl20 # or 95 mit 96 ]; 97 }; 98}