1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6 replaceVars,
7 isPy310,
8 isPyPy,
9
10 # build-system
11 cython_3_1,
12 pkgconfig,
13 setuptools,
14
15 # native dependencies
16 llhttp,
17
18 # dependencies
19 aiohappyeyeballs,
20 aiosignal,
21 async-timeout,
22 attrs,
23 frozenlist,
24 multidict,
25 propcache,
26 yarl,
27
28 # optional dependencies
29 aiodns,
30 brotli,
31 brotlicffi,
32
33 # tests
34 blockbuster,
35 freezegun,
36 gunicorn,
37 isa-l,
38 isal,
39 proxy-py,
40 pytest-codspeed,
41 pytest-cov-stub,
42 pytest-mock,
43 pytest-xdist,
44 pytestCheckHook,
45 python-on-whales,
46 re-assert,
47 trustme,
48 zlib-ng,
49}:
50
51buildPythonPackage rec {
52 pname = "aiohttp";
53 version = "3.12.14";
54 pyproject = true;
55
56 src = fetchFromGitHub {
57 owner = "aio-libs";
58 repo = "aiohttp";
59 tag = "v${version}";
60 hash = "sha256-KPPxP6x/3sz2mDJNswh/xPatcMtVdYv3aArg//7tSao=";
61 };
62
63 patches = lib.optionals (!lib.meta.availableOn stdenv.hostPlatform isa-l) [
64 ./remove-isal.patch
65 ];
66
67 postPatch = ''
68 rm -r vendor
69 patchShebangs tools
70 touch .git # tools/gen.py uses .git to find the project root
71
72 # don't install Cython using pip
73 substituteInPlace Makefile \
74 --replace-fail "cythonize: .install-cython" "cythonize:"
75 '';
76
77 build-system = [
78 cython_3_1
79 pkgconfig
80 setuptools
81 ];
82
83 preBuild = ''
84 make cythonize
85 '';
86
87 buildInputs = [
88 llhttp
89 ];
90
91 env.AIOHTTP_USE_SYSTEM_DEPS = true;
92
93 dependencies = [
94 aiohappyeyeballs
95 aiosignal
96 async-timeout
97 attrs
98 frozenlist
99 multidict
100 propcache
101 yarl
102 ]
103 ++ optional-dependencies.speedups;
104
105 optional-dependencies.speedups = [
106 aiodns
107 (if isPyPy then brotlicffi else brotli)
108 ];
109
110 nativeCheckInputs = [
111 blockbuster
112 freezegun
113 gunicorn
114 # broken on aarch64-darwin
115 (if lib.meta.availableOn stdenv.hostPlatform isa-l then isal else null)
116 proxy-py
117 pytest-codspeed
118 pytest-cov-stub
119 pytest-mock
120 pytest-xdist
121 pytestCheckHook
122 python-on-whales
123 re-assert
124 trustme
125 zlib-ng
126 ];
127
128 disabledTests = [
129 # Disable tests that require network access
130 "test_client_session_timeout_zero"
131 "test_mark_formdata_as_processed"
132 "test_requote_redirect_url_default"
133 "test_tcp_connector_ssl_shutdown_timeout_nonzero_passed"
134 "test_tcp_connector_ssl_shutdown_timeout_zero_not_passed"
135 # don't run benchmarks
136 "test_import_time"
137 # racy
138 "test_uvloop_secure_https_proxy"
139 # Cannot connect to host example.com:443 ssl:default [Could not contact DNS servers]
140 "test_tcp_connector_ssl_shutdown_timeout_passed_to_create_connection"
141 ]
142 # these tests fail with python310 but succeeds with 11+
143 ++ lib.optionals isPy310 [
144 "test_https_proxy_unsupported_tls_in_tls"
145 "test_tcp_connector_raise_connector_ssl_error"
146 ]
147 ++ lib.optionals stdenv.hostPlatform.is32bit [ "test_cookiejar" ]
148 ++ lib.optionals stdenv.hostPlatform.isDarwin [
149 "test_addresses" # https://github.com/aio-libs/aiohttp/issues/3572, remove >= v4.0.0
150 "test_close"
151 ];
152
153 __darwinAllowLocalNetworking = true;
154
155 preCheck = ''
156 # aiohttp in current folder shadows installed version
157 rm -r aiohttp
158 touch tests/data.unknown_mime_type # has to be modified after 1 Jan 1990
159
160 export HOME=$(mktemp -d)
161 ''
162 + lib.optionalString stdenv.hostPlatform.isDarwin ''
163 # Work around "OSError: AF_UNIX path too long"
164 export TMPDIR="/tmp"
165 '';
166
167 meta = with lib; {
168 changelog = "https://docs.aiohttp.org/en/${src.tag}/changes.html";
169 description = "Asynchronous HTTP Client/Server for Python and asyncio";
170 license = licenses.asl20;
171 homepage = "https://github.com/aio-libs/aiohttp";
172 maintainers = with maintainers; [ dotlambda ];
173 };
174}