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 ++ (with rustPlatform; [
54 cargoSetupHook
55 maturinBuildHook
56 ]);
57
58 buildInputs =
59 [ openssl ]
60 ++ lib.optionals stdenv.hostPlatform.isDarwin [
61 libiconv
62 ];
63
64 PSL_PATH = "${publicsuffix-list}/share/publicsuffix/public_suffix_list.dat";
65
66 nativeCheckInputs = [
67 pytestCheckHook
68 toml
69 ];
70
71 preCheck = ''
72 # import from $out instead
73 rm -r adblock
74 '';
75
76 disabledTestPaths = [
77 # relies on directory removed above
78 "tests/test_typestubs.py"
79 ];
80
81 pythonImportsCheck = [
82 "adblock"
83 "adblock.adblock"
84 ];
85
86 meta = with lib; {
87 description = "Python wrapper for Brave's adblocking library";
88 homepage = "https://github.com/ArniDagur/python-adblock/";
89 changelog = "https://github.com/ArniDagur/python-adblock/blob/${version}/CHANGELOG.md";
90 maintainers = with maintainers; [ dotlambda ];
91 license = with licenses; [
92 asl20 # or
93 mit
94 ];
95 };
96}