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 socksio,
24 pytestCheckHook,
25 pytest-asyncio,
26 pytest-trio,
27 trustme,
28 uvicorn,
29 zstandard,
30}:
31
32buildPythonPackage rec {
33 pname = "httpx";
34 version = "0.28.1";
35 pyproject = true;
36
37 disabled = pythonOlder "3.7";
38
39 src = fetchFromGitHub {
40 owner = "encode";
41 repo = pname;
42 tag = version;
43 hash = "sha256-tB8uZm0kPRnmeOvsDdrkrHcMVIYfGanB4l/xHsTKpgE=";
44 };
45
46 build-system = [
47 hatch-fancy-pypi-readme
48 hatchling
49 ];
50
51 dependencies = [
52 anyio
53 certifi
54 httpcore
55 idna
56 ];
57
58 optional-dependencies = {
59 brotli = if isPyPy then [ brotlicffi ] else [ brotli ];
60 cli = [
61 click
62 rich
63 pygments
64 ];
65 http2 = [ h2 ];
66 socks = [ socksio ];
67 zstd = [ zstandard ];
68 };
69
70 # trustme uses pyopenssl
71 doCheck = !(stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.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 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 # ResourceWarning: Async generator 'httpx._content.ByteStream.__aiter__' was garbage collected before it had been exhausted. Surround its use in 'async with aclosing(...):' to ensure that it gets cleaned up as soon as you're done using it.
102 "test_write_timeout" # trio variant
103 ];
104
105 disabledTestPaths = [ "tests/test_main.py" ];
106
107 pythonImportsCheck = [ "httpx" ];
108
109 __darwinAllowLocalNetworking = true;
110
111 # stdenv's fake SSL_CERT_FILE breaks default http transport constructor with:
112 # FileNotFoundError: [Errno 2] No such file or directory
113 setupHook = ./setup-hook.sh;
114
115 meta = with lib; {
116 changelog = "https://github.com/encode/httpx/blob/${src.rev}/CHANGELOG.md";
117 description = "Next generation HTTP client";
118 mainProgram = "httpx";
119 homepage = "https://github.com/encode/httpx";
120 license = licenses.bsd3;
121 maintainers = with maintainers; [ fab ];
122 };
123}