1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6 rustPlatform,
7 pytest,
8 runCommand,
9 boringssl,
10 libiconv,
11 SystemConfiguration,
12 patchelf,
13 gcc-unwrapped,
14 python,
15}:
16
17let
18 # boring-sys expects the static libraries in build/ instead of lib/
19 boringssl-wrapper = runCommand "boringssl-wrapper" { } ''
20 mkdir $out
21 cd $out
22 ln -s ${boringssl.out}/lib build
23 ln -s ${boringssl.dev}/include include
24 '';
25in
26buildPythonPackage rec {
27 pname = "primp";
28 version = "0.6.5";
29 pyproject = true;
30
31 src = fetchFromGitHub {
32 owner = "deedy5";
33 repo = "primp";
34 rev = "refs/tags/v${version}";
35 hash = "sha256-dexJdeNGpRsPLk8b/gNeQc1dsQLOiXNL5zgDEN9qHfQ=";
36 };
37
38 cargoDeps = rustPlatform.fetchCargoTarball {
39 inherit src;
40 name = "${pname}-${version}";
41 hash = "sha256-0mkrs50l0JEUH1WsM/Bp8AblCy6nkuohZKDsp6OVQpM=";
42 };
43
44 nativeBuildInputs = [
45 rustPlatform.bindgenHook
46 rustPlatform.cargoSetupHook
47 rustPlatform.maturinBuildHook
48 ];
49
50 # TODO: Can we improve this?
51 postInstall = lib.optionalString stdenv.hostPlatform.isLinux ''
52 ${lib.getExe patchelf} --add-rpath ${lib.getLib gcc-unwrapped.lib} --add-needed libstdc++.so.6 $out/${python.sitePackages}/primp/primp.abi3.so
53 '';
54
55 buildInputs = lib.optionals stdenv.hostPlatform.isDarwin [
56 libiconv
57 SystemConfiguration
58 ];
59
60 env.BORING_BSSL_PATH = boringssl-wrapper;
61
62 optional-dependencies = {
63 dev = [ pytest ];
64 };
65
66 # Test use network
67 doCheck = false;
68
69 pythonImportsCheck = [ "primp" ];
70
71 meta = {
72 changelog = "https://github.com/deedy5/primp/releases/tag/${version}";
73 description = "PRIMP (Python Requests IMPersonate). The fastest python HTTP client that can impersonate web browsers.";
74 homepage = "https://github.com/deedy5/primp";
75 license = lib.licenses.mit;
76 maintainers = with lib.maintainers; [ drupol ];
77 };
78}