1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 pythonOlder,
6 fetchFromGitHub,
7 substituteAll,
8 python,
9 isPy310,
10
11 # build-system
12 cython,
13 setuptools,
14
15 # native dependencies
16 llhttp,
17
18 # dependencies
19 aiohappyeyeballs,
20 attrs,
21 multidict,
22 async-timeout,
23 yarl,
24 frozenlist,
25 aiosignal,
26 aiodns,
27 brotli,
28
29 # tests
30 freezegun,
31 gunicorn,
32 proxy-py,
33 pytest-cov-stub,
34 pytest-mock,
35 pytestCheckHook,
36 python-on-whales,
37 re-assert,
38 trustme,
39}:
40
41buildPythonPackage rec {
42 pname = "aiohttp";
43 version = "3.10.10";
44 pyproject = true;
45
46 disabled = pythonOlder "3.8";
47
48 src = fetchFromGitHub {
49 owner = "aio-libs";
50 repo = "aiohttp";
51 rev = "refs/tags/v${version}";
52 hash = "sha256-c2mnt2ZQ7d7WO7Z8eDaUo9y+v0V0JwXUa1WJI9bwGTM=";
53 };
54
55 patches = [
56 (substituteAll {
57 src = ./unvendor-llhttp.patch;
58 llhttpDev = lib.getDev llhttp;
59 llhttpLib = lib.getLib llhttp;
60 })
61 ];
62
63 postPatch = ''
64 rm -r vendor
65 patchShebangs tools
66 touch .git # tools/gen.py uses .git to find the project root
67 '';
68
69 build-system = [
70 cython
71 setuptools
72 ];
73
74 preBuild = ''
75 make cythonize
76 '';
77
78 dependencies = [
79 aiohappyeyeballs
80 attrs
81 multidict
82 async-timeout
83 yarl
84 frozenlist
85 aiosignal
86 aiodns
87 brotli
88 ];
89
90 postInstall = ''
91 # remove source code file with reference to dev dependencies
92 rm $out/${python.sitePackages}/aiohttp/_cparser.pxd{,.orig}
93 '';
94
95 # NOTE: pytest-xdist cannot be added because it is flaky. See https://github.com/NixOS/nixpkgs/issues/230597 for more info.
96 nativeCheckInputs = [
97 freezegun
98 gunicorn
99 proxy-py
100 pytest-cov-stub
101 pytest-mock
102 pytestCheckHook
103 python-on-whales
104 re-assert
105 trustme
106 ];
107
108 disabledTests =
109 [
110 # Disable tests that require network access
111 "test_client_session_timeout_zero"
112 "test_mark_formdata_as_processed"
113 "test_requote_redirect_url_default"
114 # don't run benchmarks
115 "test_import_time"
116 ]
117 # these tests fail with python310 but succeeds with 11+
118 ++ lib.optionals isPy310 [
119 "test_https_proxy_unsupported_tls_in_tls"
120 "test_tcp_connector_raise_connector_ssl_error"
121 ]
122 ++ lib.optionals stdenv.hostPlatform.is32bit [ "test_cookiejar" ]
123 ++ lib.optionals stdenv.hostPlatform.isDarwin [
124 "test_addresses" # https://github.com/aio-libs/aiohttp/issues/3572, remove >= v4.0.0
125 "test_close"
126 ];
127
128 __darwinAllowLocalNetworking = true;
129
130 preCheck =
131 ''
132 # aiohttp in current folder shadows installed version
133 rm -r aiohttp
134 touch tests/data.unknown_mime_type # has to be modified after 1 Jan 1990
135
136 export HOME=$(mktemp -d)
137 ''
138 + lib.optionalString stdenv.hostPlatform.isDarwin ''
139 # Work around "OSError: AF_UNIX path too long"
140 export TMPDIR="/tmp"
141 '';
142
143 meta = with lib; {
144 changelog = "https://github.com/aio-libs/aiohttp/blob/v${version}/CHANGES.rst";
145 description = "Asynchronous HTTP Client/Server for Python and asyncio";
146 license = licenses.asl20;
147 homepage = "https://github.com/aio-libs/aiohttp";
148 maintainers = with maintainers; [ dotlambda ];
149 };
150}