1{
2 lib,
3 stdenv,
4 anyio,
5 brotli,
6 brotlicffi,
7 buildPythonPackage,
8 certifi,
9 chardet,
10 click,
11 fetchFromGitHub,
12 h2,
13 hatch-fancy-pypi-readme,
14 hatchling,
15 httpcore,
16 idna,
17 isPyPy,
18 multipart,
19 pygments,
20 python,
21 pythonOlder,
22 rich,
23 sniffio,
24 socksio,
25 pytestCheckHook,
26 pytest-asyncio,
27 pytest-trio,
28 trustme,
29 uvicorn,
30}:
31
32buildPythonPackage rec {
33 pname = "httpx";
34 version = "0.27.0";
35 format = "pyproject";
36
37 disabled = pythonOlder "3.7";
38
39 src = fetchFromGitHub {
40 owner = "encode";
41 repo = pname;
42 rev = "refs/tags/${version}";
43 hash = "sha256-13EnSzrCkseK6s6Yz9OpLzqo/2PTFiB31m5fAIJLoZg=";
44 };
45
46 nativeBuildInputs = [
47 hatch-fancy-pypi-readme
48 hatchling
49 ];
50
51 propagatedBuildInputs = [
52 anyio
53 certifi
54 httpcore
55 idna
56 sniffio
57 ];
58
59 passthru.optional-dependencies = {
60 http2 = [ h2 ];
61 socks = [ socksio ];
62 brotli = if isPyPy then [ brotlicffi ] else [ brotli ];
63 cli = [
64 click
65 rich
66 pygments
67 ];
68 };
69
70 # trustme uses pyopenssl
71 doCheck = !(stdenv.isDarwin && stdenv.isAarch64);
72
73 nativeCheckInputs = [
74 chardet
75 multipart
76 pytestCheckHook
77 pytest-asyncio
78 pytest-trio
79 trustme
80 uvicorn
81 ] ++ lib.flatten (builtins.attrValues passthru.optional-dependencies);
82
83 # testsuite wants to find installed packages for testing entrypoint
84 preCheck = ''
85 export PYTHONPATH=$out/${python.sitePackages}:$PYTHONPATH
86 '';
87
88 pytestFlagsArray = [
89 "-W"
90 "ignore::DeprecationWarning"
91 "-W"
92 "ignore::trio.TrioDeprecationWarning"
93 ];
94
95 disabledTests = [
96 # httpcore.ConnectError: [Errno 101] Network is unreachable
97 "test_connect_timeout"
98 # httpcore.ConnectError: [Errno -2] Name or service not known
99 "test_async_proxy_close"
100 "test_sync_proxy_close"
101 ];
102
103 disabledTestPaths = [ "tests/test_main.py" ];
104
105 pythonImportsCheck = [ "httpx" ];
106
107 __darwinAllowLocalNetworking = true;
108
109 meta = with lib; {
110 changelog = "https://github.com/encode/httpx/blob/${src.rev}/CHANGELOG.md";
111 description = "Next generation HTTP client";
112 mainProgram = "httpx";
113 homepage = "https://github.com/encode/httpx";
114 license = licenses.bsd3;
115 maintainers = with maintainers; [ fab ];
116 };
117}