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