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