summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/adblock/default.nix
blob: 075c73e566cb4a57cbb01d81cbea0b1fd7d65c49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
{
  lib,
  stdenv,
  fetchFromGitHub,
  fetchpatch,
  buildPythonPackage,
  rustPlatform,
  pkg-config,
  openssl,
  publicsuffix-list,
  libiconv,
  pytestCheckHook,
  toml,
}:

buildPythonPackage rec {
  pname = "adblock";
  version = "0.6.0";
  pyproject = true;

  # Pypi only has binary releases
  src = fetchFromGitHub {
    owner = "ArniDagur";
    repo = "python-adblock";
    tag = version;
    hash = "sha256-5g5xdUzH/RTVwu4Vfb5Cb1t0ruG0EXgiXjrogD/+JCU=";
  };

  patches = [
    # https://github.com/ArniDagur/python-adblock/pull/91
    (fetchpatch {
      name = "pep-621-compat.patch";
      url = "https://github.com/ArniDagur/python-adblock/commit/2a8716e0723b60390f0aefd0e05f40ba598ac73f.patch";
      hash = "sha256-n9+LDs0no66OdNZxw3aU57ngWrAbmm6hx4qIuxXoatM=";
    })
  ];

  postPatch = ''
    substituteInPlace pyproject.toml \
      --replace "0.0.0" "${version}"
  '';

  cargoDeps = rustPlatform.fetchCargoVendor {
    inherit pname version src;
    hash = "sha256-fetJX6HQxRZ/Az7rJeU9S+s8ttgNPnJEvTLfzGt4xjk=";
  };

  nativeBuildInputs = [
    pkg-config
  ]
  ++ (with rustPlatform; [
    cargoSetupHook
    maturinBuildHook
  ]);

  buildInputs = [
    openssl
  ]
  ++ lib.optionals stdenv.hostPlatform.isDarwin [
    libiconv
  ];

  PSL_PATH = "${publicsuffix-list}/share/publicsuffix/public_suffix_list.dat";

  nativeCheckInputs = [
    pytestCheckHook
    toml
  ];

  preCheck = ''
    # import from $out instead
    rm -r adblock
  '';

  disabledTestPaths = [
    # relies on directory removed above
    "tests/test_typestubs.py"
  ];

  pythonImportsCheck = [
    "adblock"
    "adblock.adblock"
  ];

  meta = {
    description = "Python wrapper for Brave's adblocking library";
    homepage = "https://github.com/ArniDagur/python-adblock/";
    changelog = "https://github.com/ArniDagur/python-adblock/blob/${version}/CHANGELOG.md";
    maintainers = with lib.maintainers; [ dotlambda ];
    license = with lib.licenses; [
      asl20 # or
      mit
    ];
  };
}